It is already clear that since the structs are value types in c#, they are stored on stack while a class object is stored on the heap (its link, course, stored on the stack).
Warning: (Yes, this may not always be true. Thanks to @Jon for fixing) But in most cases, yes!
But what about a class one of whose member is of type struct ? Now, what will the memory model look like?
By the way, how to check if any object is on stack or heap ?
Good. Some assumptions:
- This class is local inside the function.
- A structure is a
member not a variable . (Thanks to corrections.)
source share