Why to use StringBuilder
Why use StringBuilder to start with the properties of a string object.
string object when string stitching, Because of the immutability of the string, the string object will be duplicated every time, copying a copy out of the operation, and its own strings remain in memory, a large number of temporary fragments will cause negligible performance loss. Therefore, it is recommended to use StringBuilder
the simple way to use StringBuilder
string S1 = "33";
String s2 = "44";
String s3 = "55"; The demand is to S1 S2 S3 together. This is a typical string concatenation.
With StringBuilder, no useless temporary strings are generated.
StringBuilder SB =new StringBuilder ();
Stitching method One
Sb. Append (S1);
Sb. Append (S2);
Sb. Append (S3);
//splicing mode two
Because the Append () method returns a This, which is the object itself. So you can use this method.
Chained programming jquery is commonly used in this way
Sb. Append (S1). Append (S2). Append (S3);
Finally put SB. ToString () Just a little bit better.
The Ps:appendline () method can automatically add a carriage return.
. NET in the StringBuilder