Packing and unpacking: any value type and reference type can be Object (Object) type conversion. Boxing refers to implicit or explicit conversion of a value type into Object Type, or convert this value type to an interface type applied by this value type ( Interface-type ). To pack a value of the value type, create Object Instance and copy the value to this Object , Boxed Object The data in the object is located in the heap, and the address in the heap is located in the stack. The value of the boxed type is assigned to the object as a copy. For example:
Int I = 10;
Object OBJ = I ;//Implicit packing
Object OBJ = Object (I );//Explicit packing
If (obj is int) // int
Console. writeline ("OK ");
Console. writeline (obj. GetType (); // system. int32
There are two ways to view the type of raw data packaged in the referenced object after packaging. To determine whether the original type is a given atomic type, useIsTo return a string, you can useObjectClassGetTypeMethod.
Box-breaking conversion refers to explicitly converting an object type into a value type, or explicitly converting an interface type into a value type that executes this interface. Note that the packing operation can be performed implicitly, but the unpacking operation must be explicit. The unpacking process is divided into two steps: first, check the object instance to see if it is a boxed value of the given value type. Then, copy the Instance value to the value type variable. For example:
Int I = 10;
Object OBJ = I;
Int J = (INT) OBJ;
There are two ways to view the type of raw data packaged in the referenced object after packaging. To determine whether the original type is a given atomic type, useIsTo return a string, you can useObjectClassGetTypeMethod.
Box-breaking conversion refers to explicitly converting an object type into a value type, or explicitly converting an interface type into a value type that executes this interface. Note that the packing operation can be performed implicitly, but the unpacking operation must be explicit. The unpacking process is divided into two steps: first, check the object instance to see if it is a boxed value of the given value type. Then, copy the Instance value to the value type variable. For example:
Int I = 10;
Object OBJ = I;
Int J = (INT) OBJ;