How the StringBuilder class is implemented? Does it internally create new string objects each time we append?

In .NET 2.0 it uses the String class internally. String is only immutable outside of the System namespace, so StringBuilder can do that. In .NET 4.0 String was changed to use char[]. In 2.0 StringBuilder looked like this public sealed class StringBuilder : ISerializable { // Fields private const string CapacityField = “Capacity”; internal const … Read more

When to use StringBuilder?

I warmly suggest you to read The Sad Tragedy of Micro-Optimization Theater, by Jeff Atwood. It treats Simple Concatenation vs. StringBuilder vs. other methods. Now, if you want to see some numbers and graphs, follow the link 😉

String, StringBuffer, and StringBuilder

Mutability Difference: String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. So when the application needs to be run only in a single thread then … Read more