juniorcsharp-basics
Value types store data on the stack (int, struct, enum). Reference types store a reference to an object on the heap (class, string, array).
Value types: copied on assignment, live on the stack (or inline in objects). Inherit from System.ValueType. Reference types: only the reference is copied, the object is on the managed heap. When passing to a method, value type is copied, reference type is not (but the reference itself is copied). Nullable<T> wraps a value type to allow null.
struct Point { public int X; public int Y; }
class User { public string Name; }
var a = new Point { X = 1, Y = 2 };
var b = a; // копия
b.X = 99; // a.X всё ещё 1
var u1 = new User { Name = "Alice" };
var u2 = u1; // ссылка
u2.Name = "Bob"; // u1.Name тоже "Bob"When yes
struct for small immutable data (< 16 bytes). class for everything else
When no
struct for large objects or with mutable state — expensive copies
Interview tip
Frequently asked: string is a reference type but behaves like value (immutable). That's because string is immutable, not because it's a value type.