Skip to content


by Alex Peck on July 27th, 2009

Since strings in .NET are immutable, StringBuilder is used when you need to work with mutable string data – i.e. appending, removing, replacing, or inserting characters.

MSDN states that most of the methods that modify an instance of this class return a reference to that same instance. Since a reference to the instance is returned, you can call a method or property on the reference. This can be convenient if you want to write a single statement that chains successive operations one after another.

Performance consideration: StringBuilder is only really advantageous when working with larger string operations, like concatenating tens of strings in a loop. This is due to the overhead of creating a StringBuilder vs a string – StringBuilder is obviously more complex. Rico Mariani provides similar advice.

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS