Drill down into C # data types

Source: Internet
Author: User

Value type: All references to value types are stored in the stack

Value type Assignment principle: The true value copied on the stack

Reference type:  

Properties of real objects on the heap that are stored on the real object itself

(1) Open space on the heap to save data
(2) The memory address on the heap is stored in the stack space
(3) Pointing from the stack to the real object on the heap

For value types, different variables are allocated different storage spaces, and the value of the variable is stored in the storage space.

The value of the variable is passed by the assignment operation, and changing one variable does not affect the value of the other variable.

For reference types, the assignment is to pass a reference to the original object to another reference. Array.

When an array reference is assigned to another array reference, the two references point to the same array, which is to point to the same block of storage space

Structure:

Definition of structure

Grammar:

Access modifier struct struct name {//struct}

You can have fields in the @ structure, or you can have methods

When @ is defined, the fields in the struct cannot be assigned an initial value

@ You cannot have attributes when you are not going to the new struct class

After you declare an object of a struct, you must assign an initial value to all members of the struct.

Packing and unpacking

A value type is converted to a reference type to be boxed, and vice versa to be a unpacking

      

        Reference method parameter passing

(Basic data types, such as, shape, float, character, bool, and struct are value types; arrays, interfaces and classes are reference types)

When a value type parameter is passed using a value method (without a ref decoration), the modification of the parameter in the method does not persist

When a reference type parameter is passed using a value method (without a ref decoration), the modification of the parameter in the method is preserved

When you pass a value type or reference type parameter by using a reference method (with ref decoration), the modification of the parameter in the method is preserved

  

Drill down into C # data types

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.