Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0250 StringBuilder class

StringBuilder from System.Text namespace is a mutable string. The following code appends strings to StringBuilder. using System; using System.Text; class Sample { public static void Main() { StringBuilder sb = new StringBuilder(); string[] strs = new string[] { "a", "v", "c" }; foreach (string s in strs) { sb.Append(s); } Console.WriteLine(sb); } } The output: avc Using Append method from StringBuilder is more efficient than using + to add strings together.