The StringBuilder Class

As stated numerous times already, the immutable nature of strings can be a blessing and a curse. The latter is especially true if lots of string manipulations have to be made, which effectively results in the creation of lots of intermediary string objects. Although short-lived objects are cleaned up pretty effectively by the garbage collector, having a lot of those, each of which can be substantially big, is suboptimal too. You can avoid this by making use of the System.Text.StringBuilder class.

Note: Default using Directives

A few releases of Visual Studio ago, a using directive for the System.Text namespace was added to the default template for newly created code files. An obvious reason for its inclusion is the frequent ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.