Search This Blog

Tuesday, October 22, 2013

Boxing and Unboxing C#


Boxing is the process of converting a value type to the type object. When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap.
Unboxing extracts the value type from the object.

Example:

int i = 10;
object o = i; // boxes i
i = (int)o;   // unboxing