A good brain is better than a bad pen, always remember, write it down
Still handling address: http://blog.csdn.net/qq_28187979/article/details/76607253
--------------------------------------------------------------------------------------------------------------- --------
Recently on these silly points are not clear, in the online collection of some information, now summed up.
The string is the base type, and the first statement, in effect, is to create an object of type string named S1, and the system allocates enough memory for S1 to hold the data in S1. The second statement, instead of adding the string "Ceshi" to the address pointed to by S1, creates a new string instance, allocates enough memory to it, puts "test" into it, adds "Ceshi" to it, and then updates the memory address stored in the S1 variable, making S1 point to the new string object , the old string object is destroyed. That is, each time you add or delete a string type, a new string object is created and the old string object is destroyed. If you perform string operations frequently, you can affect system performance. This is also why a string is an immutable object. Therefore, if you need to modify the string frequently, it is recommended to use StringBuffer or StringBuilder.
string S1 = "Test";
S1 + = "Ceshi";
StringBuilder and string initialization, when string is initialized, the system allocates enough memory to hold its defined string literals, but StringBuilder has many constructors to initialize the initial size of the current instance and the maximum number of characters that can be stored. When used, it is best to set the capacity to the maximum length of the string, to ensure that the StringBuilder does not need to reallocate memory, and if the number of characters exceeds the set maximum capacity, the. NET runtime automatically allocates memory and doubles. That is, StringBuilder can explicitly set the size of the allocated memory, and string can only allocate enough memory by the system based on the size of the initialization string.
In the above case, StringBuffer and StringBuilder are the same, the latter faster than the former, but the former is thread-safe, suitable for multi-threaded use, the latter is thread non-security, more suitable for single-threaded use.
The difference between c#:string, StringBuffer and StringBuilder