Skip to content
Mario Gutierrez edited this page Jan 7, 2017 · 1 revision

Every time you assign a ValueType to a ReferenceType, e.g.,

int f = 5;
object oa = f;

C# does a 'box' operation: allocates an object on the heap and moves the value from the stack to the new object.

C# does an 'unbox' operation to do the inverse, and requires casting:

int g = (int)oa;

This is very inefficient speed-wise and memory-wise.

Clone this wiki locally