C# & CLR Internals (50 Qs)•Part 1: Core Language, CLR & Memory Architecture (1 - 10)
What is the difference between Value Types and Reference Types in C#?
senior LevelSystem Design
In Simple Words:
- Value Types (
struct,enum,int,bool,double): Stored inline where declared (usually on the stack for local variables, or inside the heap object if part of a class). Contain the raw value. Assignment copies the entire value. - Reference Types (
class,interface,delegate,record,string): Allocated on the managed heap. The variable holds a pointer (reference) to the heap memory address. Assignment copies only the pointer reference.