String type in C #

Source: Internet
Author: User

In C #, the string type is actually the reference type. The String object is allocated to the stack instead of the stack. Therefore, when a string variable is assigned to another string, two references to the same string in memory are obtained. However, there are some differences between string and reference types in common operations. For example, strings cannot be changed. If you modify one of the strings, A New String object is created, and the other string does not change. Run the following code:

String A = "A1 ";

String B = "B" +;

Console. writeline ("B is:" + B );

A = "A2 ";

Console. writeline ("A is:" + );

Console. writeline ("B is:" + B );

Console. Read ();

 

 

Output result:

BA1

A2

BA1

 

String type in C #

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.