Comparing the performance of String and StringBuilder, we can find a lot on the Internet, but most of them compare the connection performance of String. The efficiency of String connection String + = is indeed less than that of StringBuilder, you can find many examples online. In this way, we are assimilated by these tie evidence. We began to use StringBuilder in flood mode. StringBuilder is good for B String, and some friends even went further to encapsulate StringBuilder and reload operators to create classes, to replace String.
But not some String operations are not as good as StringBuilder?
Differences between String and StringBuilder:
1. Although both are reference types, String in C # is usually treated as a struct. For example, we write:
String text = "abc"; text. Replace ("a", "B"); is it true that the value of text changes? Obviously, we have to write:
Text = text. Replace ("a", "B"); are we aware of the String as a function parameter?
If you change to StringBuilder, you do not need the code in step 3.
2. The methods of String and StringBuilder are not exactly the same. This is nonsense. Of course it won't be the same. Well, they include the same and similar functions.
In the past, I learned that StringBuilder is very efficient in connecting strings. Since then, I love it. As long as the String method is available in StringBuilder, it will give priority to StringBuilder, without asking why, there is a belief in my mind. StringBuilder is really a man, really man!
Here, I began to have some doubts. Is the StringBuilder method better than the String method? Exploration spirit, yeah!
I use VS2008. See the following code: