where will the class be stored if it has a struct variable?
.net, c#, c#-4.0
Solution
The class itself will be a reference type, so instances of it will be kept on the heap.
The property that is a `struct` is an integral part of the instance (i.e., of the object), and so will also be kept on the heap, just like the `int` and `enum` properties of that object.
Note: There will be no references to the `struct` property, just like there are no references to the `int` and `enum` properties.
Problem
It is already clear that `since the structs are value types in c#, they are stored on stack` whereas `a class object is stored on the heap` (its reference, of-course stored on stack). Warn: (Yes, this might not always be true. Thanks to @Jon for correction) But in most cases, yes! But, what about`a class one of whose member is of type struct` ? Now, how will the memory model be? BTW, how do I check if some object resides in `stack` or `heap` ? Okay. Some assumptions: - This class is local inside a function. - The struct is a `member` not a `variable`. (Thanks to the corrections.)