The constancy of C # strings

Source: Internet
Author: User

1 stringstr1="AA";2 3 stringStr2="AA";4 5 6 STR1,STR2, the address of the heap space that the variable points to is the same. The contents of the stack space are not the same. 7 8 9 Ten  //the role of new One*1open up a suitable size heap space or constant area space A*2. Create an Object -*3. Call the constructor -*4return to open space address the stringSTR3 =New string(New Char[]{'a','a'}); -  - stringSTR4 =New string(New Char[]{'a','a'}); -  +  -STR3,STR4, the address of the stack space and the address of the heap space are not the same.



Summary: 1. Create a string, the system will first scan the constant area (heap space), there are no strings of the same value, if any, directly return the corresponding constant area (heap space) address.
2. If the string is modified ... However, the string can not be modified, the system will first scan the constant area has no modified values, if any, directly return, if not, to open up new space to return.

The constancy of C # strings

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.