Boxing and Unboxing in C#

Boxing and Unboxing is an important concept in C#. Type systems in C# contains three ways of Data Types. Value Type, Reference Type and Pointer Type. 

Boxing

The process of Converting Value Type to Reference Type is called Boxing

Boxing is conversion process where value type is converted into Object (reference type)

Value is stored on Stack of Memory and copied to the object stored on heap memory.

int number = 65;  
object obj = number;  
System.Console.WriteLine("Object - type value of obj is : {0}", obj);

Unboxing

The process of Converting reference type into value type is known as Unboxing.

It is explicitly converts from Object data type to value data type

int number = 65;  
object obj = number;  
System.Console.WriteLine("Object - type value of obj is : {0}", obj);
int number2 = (int)obj;  // Unboxing
System.Console.WriteLine("Object - type value of obj is : {0}", number2);