What is the difference between value types and reference types in C#?
cs-jun-001
Your answer
Answer as you would in a real interview — explain your thinking, not just the conclusion.
Model answer
Value types — structs, primitives like int and bool, and enums — store their data directly on the stack or inline within a containing object. Assignment creates an independent copy, so changing one variable does not affect the other. Reference types — classes, interfaces, delegates, arrays — store a pointer to heap-allocated memory. Assignment copies the reference, meaning two variables can point to the same object. Modifying the object through one variable is visible through the other. Null assignment is only valid for reference types unless you use Nullable<T> (int?).
Code example
int a = 10;
int b = a; // copy of value
b = 20;
Console.WriteLine(a); // 10 — unaffected
var list1 = new List<int> { 1, 2, 3 };
var list2 = list1; // copy of reference
list2.Add(4);
Console.WriteLine(list1.Count); // 4 — same object
Follow-up
When would you choose a struct over a class? What is the general guideline for struct size in .NET?