As you know the C# Type contains three Types

  • Value Types
  • Reference Types
  • Pointer Types

Converting a value type to a reference type called Boxing and vice versa is called Unboxing.

Boxing

Boxing is an implicit conversion of a value type to a type object or to any type of interface implemented by this value type.

int value = 1234;
object o = value; 

Boxing is used to store value types in the garbage-collected heap. Boxing a value type allocates an object instance on the heap and copies the value into the new object.

Unboxing

Unboxing extracts the value type from the object

object o = 1234;
int value = (int)o;// unboxing

Unboxing is an explicit conversion from the a object to the value type or from an interface type to a value type that implements the interface