Packing and splitting
Packing and unpacking are the core of the C # type system. through packing and unpacking. it can build a bridge between the value type and the reference type. in other words. you can easily convert the value type to the reference type. the installation and unpacking can be used to check the type system in a unified manner. any type of value can be processed by object.
Phase: Convert the value type to the object type, or convert it to the interface type executed by the value type. pack a value of the value type, that is, create an object and assign this value to this object. there are four common packing conversions:
Convert from any value type to: 1: object type, 2: system, valuetype type, 3: Any interface type implemented by the value type, and from Enumeration type to system. Enum type.
Note that packing conversion means copying a value to be installed. this is very different from converting a reference type to an object type. in the latter, the converted value continues to reference the same instance. it is just an object type.
Example:
Int I = 100;
Object OBJ = I;
Binning: The binning process is opposite to the assembly phase. The core of the process is to convert a reference type display to a value type, or convert an excuse type to a value type that implements this interface. there are also four common unpacking operations: 1: Converting from object type to any value type 2: From system. valuetype type conversion to any interface type 3: Convert from any interface type to any value type that implements this excuse 4: From system. convert the enum type to the enumeration type. the unpacking process is divided into two steps: 1. check whether the object instance is a value of the specified value type. 2. copy the value from the object instance.
Unpack:
Int I = 100;
Object OBJ = I;
Int J = (INT) I;