This example describes the. NET in StringBuilder usage. Share to everyone for your reference. The specific analysis is as follows:
Why to use StringBuilder
Why use StringBuilder to start with the attributes of a string object.
String objects are concatenation, because the string is not denatured, the string object will be spliced each time, will copy a copy out of the operation, while the string is still in memory, a large number of temporary fragments can cause negligible performance loss. So it is recommended to use StringBuilder in a large number of string concatenation
the simple way of using StringBuilder:
Copy Code code as follows:
string S1 = "33";
String s2 = "44";
String s3 = "55"; The demand is to put the S1 S2 S3 stitching together. This is a typical string concatenation.
With StringBuilder, no unwanted temporary strings are generated.
StringBuilder SB =new StringBuilder ();
Stitching Way 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 approach.
Chained programming is often the way in jquery
Sb. Append (S1). Append (S2). Append (S3);
Finally put SB. ToString () will be fine.
The Ps:appendline () method can automatically add a carriage return.
I hope this article will help you with your. NET programming.