Search This Blog

Tuesday, May 20, 2014

StringBuilder C# Example

C# > Text > StringBuilder 

StringBuilder is used when

  • you want to create or modify a string without creating a new object
  • increase performance when concatenating many strings together in a loop.


Example:


StringBuilder str = new StringBuilder("Product 1");

str.AppendLine(); // new line
str.Append("Product 2");
str.AppendLine();
str.AppendFormat("Total {0:C} ", 40);

textBox1.Text = str.ToString();