StringBuilder
A .NET class that builds text in one growable buffer, avoiding a new string for every piece appended.
In more detail
Because strings are immutable, adding to a string in a loop creates a throwaway string each time. StringBuilder appends into one buffer and produces the final string with ToString.
Example
var sb = new StringBuilder(); sb.Append(1).Append(';');Related terms
- string — The type for text values, such as a name or an email address.
- allocation — Reserving memory for a new object on the heap.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices