Difference between value type and reference type

Source: Internet
Author: User

The method for passing internal values is different:

The Value Type copies its own value and passes it to other function operations. No matter how the copied value is changed, its own value will not change.

The reference type is to pass its memory address to other function operations. The operation is to reference the type value itself, so the value is changed by the function.

For example
Int A = 1;
Int B =;
B ++;
At this time, B is 2, and A is still 1.
Let's look at the reference type again. For example, there is a user type
User U1 = new user () {name = "Zhang San "};
User U2 = U1;
U2.name = "Li Si ";
At this time, the names of U2 and U1 are Li Si, because when U2 is U1, u1 and U2 will point to the address in the same memory. Changing U2 is equivalent to changing u1,

 

Difference between value type and reference type

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.