Advertisement
Beginner C#, Value vs Reference Types

Where are value types and reference types stored?

Short answer

Local value types typically live on the stack; reference-type objects live on the managed heap with the reference on the stack. Value-type fields inside a class live on the heap with the object.

Save C# mock interview
Advertisement
AModel answer
Local value types typically live on the stack; reference-type objects live on the managed heap with the reference on the stack. Value-type fields inside a class live on the heap with the object.
class Box { public int N; }   // N lives on the heap inside Box
int local = 5;                // stack
Real-world example
Understanding this explains why large structs are costly to copy.