Inboxing and unboxing in C # (easy to understand ),

Source: Internet
Author: User

Inboxing and unboxing in C # (easy to understand ),

Packing and unpacking are the operations to convert the value type and the reference type.

Packing: implicitly converts a value type to an object type, or converts the value type to an interface type applied to this value type, and packs a value type, creates an object instance and copies the value to the object.
Unpacking: In contrast to packing, unpacking refers to explicitly converting an object type into a value type, or explicitly convert an interface type into a value type that executes the interface.
Object obj = null;
Obj = 1; // pack the value type into a reference type.
Int num = (int) obj; // unpack, display type conversion.

The binning operation is opposite to the packing operation. It is used to convert the reference type value stored on the stack to the value type and give the value type variable.

The packing and unpacking operations require additional cpu and memory resources. Therefore, a generic type is introduced after c #2.0 to reduce the consumption of packing and unpacking operations.

Related Article

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: info-contact@alibabacloud.com 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.