. Net learning-> value type, reference type, packing, and unpacking

Source: Internet
Author: User

Summary:

A. variables: (two perspectives)

 

1. Declare the location angle

Local variables: (method variables) stored on the stack-with the lifecycleCodeBlock is recycled by the system.

Global variables: (class variables) stored on the stack-as the object where it is located is reclaimed

 

2. Data Type Angle

Value Type: directly store the data itself

Reference Type: storage address -- pointing to an object-object survival on the heap

 

B. Comparison of the structure and class in the memory (obviously it can be seen as memory allocation)

From this point, we can also see that the storage location of the variable, the value type is stored in the declared place (may be in the heap or stack), and the reference type is stored in the heap.

 

C. Packing

When value type variable (a) is assigned to reference type variable (B), CLR will copy this value type variable (a) to the stack. At this time (B)
It refers to the copy of the reference on the heap (a). This process is called packing.

Is the Best Presentation:

 

 

D. binning

To copy the packed values back, you must display them for type conversion.

Is the Best Presentation:

 

 I would like to make a summary and make more improvements. I hope I can stay in the blog Park for a long time! Thank you for your guidance!

 

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.