where will the class be stored if it has a struct variable?

Viewed 968

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:

  1. This class is local inside a function.
  2. The struct is a member not a variable. (Thanks to the corrections.)
2 Answers
Related