What is the difference between System.String and
System.StringBuilder classes?

Answer Posted / shyam vishwakarma

String and StringBuilder class stores strings. But when you
cannot change a String object after creating one.
eg: String name = "Prasad";
By saying you cannot change the name object means you cannot
change the value in name object internally. When you change
the name object value to something else, a new String object
is creating in memory and assign the new value.

eg: name = "Prasad Reddy";

A new name object is creating in memory and the value
"Prasad Reddy" is assinging to the newly created space.

But StringBuilder class occupies the same space even if you
change the value.

If you are doing string concatenation StringBuilder class is
far better in performance than String class.

You can use StringBuilder's Append() method to use
concatenation.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is multiple interface in c#?

706


What is static classes?

663


Can a loop recorder detect a heart attack?

767


What is razor view in c#?

625


What is the relation between classes and objects?

702


Can an abstract class inherit from another abstract class c#?

711


Why do we use generics in c#?

723


What is the difference between new and override in c#?

735


How to update the gui from another thread in c#?

734


write a C# Program add two matrix ?

746


What is appdomain in c#?

662


Is array passed by reference in c#?

707


Why do we use static methods in c#?

732


How long can a string be c#?

656


Does c# support multiple inheritance (mi)?

701