1

I know that the structures are not saved in heap. The class is saved in heap. That is clear but where will be saved structure if it contains the field of some class? For example:

class TestClass
{
    public string Name;
}

struct MyStruct
{
    public TestClass myClass;
}
user1706449
  • 159
  • 1
  • 1
  • 9

1 Answers1

0

Storage of value types and reference types are implementation details, they are not guaranteed to stay fixed in implementations of the CLR or future versions of implementations.

To quote from the MS spec:

In the Microsoft implementation of C# on the desktop CLR, value types are stored on the stack when the value is a local variable or temporary that is not a closed-over local variable of a lambda or anonymous method, and the method body is not an iterator block, and the jitter chooses to not enregister the value

In your example, the answer is that... it depends.

I'd recommend having a read of Eric Lippert's blog posts on the truth about value types and the that the stack is an implementation detail this for more information.

Rich O'Kelly
  • 41,274
  • 9
  • 83
  • 114