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 abouta 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
membernot avariable. (Thanks to the corrections.)