Transfer from http://jingyan.baidu.com/article/454316ab57a772f7a7c03aea.html
. NET contains a special object class that can accept values of any data type, and when the type passed or assigned is not a specific data type, the object class provides a common way to pass parameters and assign values. The value assigned to object must be a reference type and be stored in the managed heap.
Packing:
int age = 24;
Object refage= age;
As you can see, the first statement creates a variable age and places the value in the managed stack;
The second statement assigns the value of age to the reference type. It places the value 24 in the managed heap.
This value type is packaged as a reference type of procedure, called boxing.
Unpacking:
Conversely, the process of converting a reference type to a value type is called unpacking. Unpacking will cast the object to its original type. Unboxing the previous object.
int newage = (int) refage;
String newage = (string) refage;
The value of the unboxing must have the same type as the variable to which it is to be converted.
C # Boxing and unpacking principles