Concept understanding-packing and unpacking

Source: Internet
Author: User
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.
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.
Int I = 100;
Object OBJ = I;
Int J = (INT) I;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.