What are the disadvantages of using a StringBuilder?

Posted by stickman on Stack Overflow See other posts from Stack Overflow or by stickman
Published on 2011-06-26T23:49:00Z Indexed on 2011/06/27 0:22 UTC
Read the original article Hit count: 148

Filed under:
|
|

I know that StringBuilder is more efficient than a normal string when processing code which modifies the string value a lot because although strings act like value types, they are actually reference, which makes them immutable so every time we change it, we need to create a new reference in memory.

My question is that, why doesn't .NET just use stringBuilder by default? There must be some disadvantages of it over just using String. Can anyone tell me what they are?

The only thing I can think of is perhaps it is a heavier object and it takes more time to instantiate so if you aren't changing the string too much, this would override the benefits of StringBuilder

© Stack Overflow or respective owner

Related posts about string

Related posts about .net-4.0