Packing: To convert a value type to a reference type, a mechanism called packing is required. Int32 A = 5; object o =;
During binning of the value type, the following internal events occur:
1. First, allocate the memory in the managed heap. The size is the amount of memory required for value-type fields plus the size of additional members (type object pointers and synchronized index blocks.
2. Copy the value type field to the newly allocated heap memory.
3. Return the object reference.
Unpack: First, unpacking is not the inverse process of packing. It is actually the process of getting a pointer, pointing to the original value type in an object.
After unpackingFollowed by the field copy process.
When disassembling an object, you can only convert it to a value type that is not originally boxed. Example: int32 x = 5; object o = x; int16 y = (int16) O;
In this case, an exception occurs. It can be written as follows: int16 y = (int16) (int32) O; must first be converted to the original type.