Skip to content

Value Types vs. Reference Types

Question

Describe the differences between reference types and value types.

Short interview answer

A value-type variable contains its value, so assignment copies that value. A reference-type variable contains a reference to an object, so assignment copies the reference and both variables can refer to the same object.

Detailed answer

int, bool, enum, and struct are value types. class, string, array, delegate, and interface types are reference types. The practical difference is copy behavior:

var left = new Point { X = 1 };
var right = left;
right.X = 2;             // left.X is still 1.

var first = new Customer { Name = "Ada" };
var second = first;
second.Name = "Grace";  // first.Name is now "Grace" too.

The first assignment copies a value; the second copies a reference. Storage location is an implementation detail; do not reduce the distinction to “stack versus heap.”

Sources