Reference types

The memory address is stored against the variable instead of the value, this is stored on the heap. Multiple variables can reference the same object in memory. Different references to the same object can affect each other.

var myClass = new MyClass();

var myOtherClass = myClass;

Types: classes, interfaces, arrays, strings, hashtables, tuples

Value types

The value itself is stored against the variable on the stack. Each variable has its own space used in memory. One value type cannot affect another.

Types: int, struct, enum, bool, float, char, double, decimal. sbyte, short, uint, ulong, ushort

Boxing and unboxing

Boxing is when you convert a value type to a reference type, and unboxing is when you convert an object to a value type.

References

Advertisements