Forum guidelines
Advantage of using StringBuilder in C#
Posted By Amit Maheshwari on 12 Feb 2012
Hi friends,

I want to know that what's the advantage of using System.Text.StringBuilder over System.String?

Re: Advantage of using StringBuilder in C#
Posted By Vulpes on 12 Feb 2012  
The StringBuilder class enables you to (in effect) create a mutable string i.e. a string that can be changed.

You can change existing characters, insert or add new ones or delete characters and it's still the same object. It automatically increases its size when needed by doubling the size of its internal buffer.

In constrast, the String class produces immutable strings. Methods which appear to change the string do in fact return a new one.

Because StringBuilders are mutable they are useful for operations such as concatenation on a large number of strings, where they are more performant than ordinary strings and ease pressure on the garbage collector

Re: Advantage of using StringBuilder in C#
Posted By Jignesh Trivedi on 12 Feb 2012  

string is immutable and you allocate new memory each time you append strings.

StringBuilder allows you to add characters to an object and when you need to use the string representation, you call ToString() on it.

please refer.

hopr this help.

Download Free e-Books


Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.