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