2018-08-12 23:03:05
Boxing is the process of converting a value type to a object type or to any interface type implemented by this value type. When the CLR is boxing a value type, it wraps the value inside the System.Object and stores the latter on the managed heap. Unboxing extracts the value type from the object. boxing is implicit; unboxing is explicit. The concept of boxing and unboxing is the basis for a unified view of the type System C #, where any type of value is treated as an object.
Icon:
Understanding: Boxing (boxing) assigns a value type to a reference type. From the stack (stack) to the heap (heap).
Unpacking (unboxing) returns the reference type to the value type variable. From heap to stack. Although not necessarily successful.
Example: Boxing
1 int 123 ; 2 // The following line boxes I. 3 object o = i;
Example: Unboxing
1 123 ; 2 i = (int) o; // Unboxing
Boxed and unboxing of C #