Possible Duplicate:
String vs StringBuilder
i know .NET Strings are immutable which is the reason why a new string object is created every time we alter it (insert, append, remove, etc.).
That sounds reasonable, so why do we still use the .NET String class functions and not the faster StringBuilder?
StringBuilderis faster for repeated (non-compile-time) concatenations in a loop.For ordinary string operations, they perform equivalently.
In particular,
a + b + cis compiled asString.Concat(a, b, c), which allocates a single buffer and is as fast or faster than a string builder.StringBuilderis only faster than multiple separateConcats, since eachConcatwill need to make a new buffer.