Value types and reference types

Source: Internet
Author: User

1.

A reference type indicates that the data you are manipulating is the same, that is, when you pass a parameter to another method and you change the value of the variable in another method, the value of the variable passed in when the method is called will also change .
A value type means copying a current variable to a method, and when you change the value of the variable in this method, the value of the initial life variable does not change .

2.
Value types are common basic data types: numeric, character, Boolean

Reference type: All types except basic data types are referred to as reference types

3.
For example, there is a rectangle in memory (assuming), with a number n

Value types are basic data types, such as Int,float,byte,double,boolean,char.

Value passing is a copy of the number of n in the rectangle to other parameters or methods, no matter how you operate, the rectangle and the number of n does not change.

Reference types are objects, such as arrays, strings, and so on.

Reference passing is to pass the rectangle's address to another parameter or method, the other parameter or method will get the number n through this address, if the operation of this address, the value of the rectangle will change.

The action is on its replicator relative to the value type, and the operation is on its own relative to the reference type.

4, value delivery: The basic data type assignment is the value of the pass, the value passed is a real variable value, is the transfer of the original parameter copy, the value is passed, the argument is passed to the value of the parameter, the parameter changes without affecting the argument.

Reference passing: Assignment between reference types is a reference pass. Reference passing is the object's reference address, which is itself (its own most popular understanding). Reference passing: The address is passed, that is, the address of the argument to the formal parameter

, the parameters are changed, and the arguments are changed, because they point to the same address.

Value types and reference 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.