Difference between string and StringBuilder in c#

In this post,we will learn about Difference between string and StringBuilder in C# with an example.


In my previous posts I have explained various topics like Difference between a struct and a class in C#, Boxing & Unboxing in C# ,Dynamic Type In C#, Named Arguments In C#, Basics Of Pointers In C#, Get site visitor count in asp.net, Convert generic list to datatable in Asp.Net C#.Net, Abstract Class in C# with Example.

Now in this post, I will explain about Difference between string and StringBuilder in C# with appropriate example. StringBuilder and string both use to store and manage string value in variable but both have many differences on the bases of instance creation and also for performance.


String data type is an immutable object. So, When we create string object in program, we cannot change that object in any operations viz. insert new value, replace or append any value with existing value in string object, when we have to do some operations to change string simply it will dispose the old value of string object and it will create new instance in memory for storing the new value in string object.


System.Text.Stringbuilder is mutable object which also hold the string value, mutable refer to once we create a System.Text.Stringbuilder object we can use this object for any operation like insert value in existing string with insert functions also replace or append without creating new instance of System.Text.Stringbuilder for every time so it’s use the previous object so it’s work fast as compare than System.String.


I hope you got an idea about Difference between string and StringBuilder in C#.
I would like to have feedback from blog my readers.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *