Trap ~ Do not be ambiguous about the reference type!

Source: Internet
Author: User

The reference type is always mysterious because it stores the memory address. For a variable of the reference type, when you perform the value assignment operation, it is transmitted in the form of an address, when you operate on a reference type in a code segment, it will respond to the original object. Below I will talk about several common usage of the reference type:

Case 1: Will modifying the content element of a set variable affect the original object?

A: Yes, it will be reflected in the meta set.

Code:

            List<Yinyong> yiyi =  List<Yinyong> {  Yinyong { ID = , Name =  },  Yinyong { ID = , Name = ].Name =             Console.WriteLine(yiyi[

Scenario 2: After defining a set variable, add some of its elements to another set, and modify its elements in another set, will it be reflected in the original set?

A: Yes, it will be reflected in the meta set.

Code:

            List<Yinyong> yiyi =  List<Yinyong> {  Yinyong { ID = , Name =  },  Yinyong { ID = , Name = <Yinyong> temp =  List<Yinyong>=> i.ID ==  ( item = 

Case 3: After defining the set variable, pass it as a parameter to other methods. Will the modification of this object in other methods be reflected in the original set of the original method?

A: Yes, it will be reflected in the meta set.

Code:

    Main(<Yinyong> yiyi =  List<Yinyong> {  Yinyong { ID = , Name =  },  Yinyong { ID = , Name =                              ModifySet(List<Yinyong>].Name = 

 

Well, after mastering the above three points, we will be more comfortable writing code. Only by mastering the basic knowledge can we design better programs!

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.