Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.31/5 (6 votes)
See more:
What is the difference between string and stringbuilder c#?
Posted
Updated 17-Aug-11 9:14am
v2
Comments
Tarun.K.S 17-Aug-11 15:14pm    
Just one "?" is enough. Stop putting multiple ????.

There is an answer to the question here; http://www.dotnetuncle.com/difference/41_string_stringbuilder.aspx[^]

In its simplest form, basically stringbuilder is more efficient at handling string concatenation operations.
 
Share this answer
 
Comments
Espen Harlinn 17-Aug-11 18:48pm    
Right, my 5
A StringBuilder wears a hardhat, a string doesn't. Seriously though...

A string is deleted and reallocated when you concatenate it, where a StringBuilder isn't. StringBuilders are much more efficient.

BTW, google is free, and this is an easily found answer there.
 
Share this answer
 
Comments
Espen Harlinn 17-Aug-11 18:47pm    
Right, my 5 :)
This article goes a bit more into the details than the note posted at dotnetuncle
String Vs StringBuilder (C#)[^]
 
Share this answer
 
Comments
Abhinav1986 29-Oct-13 6:17am    
sss
 
Share this answer
 
Comments
Espen Harlinn 17-Aug-11 18:50pm    
Nice article, my 5
Mohammad A Rahman 17-Aug-11 19:34pm    
Thanks Espen :)
StringBuilder is a mutable class, meaning you can insert/append/replace/etc. without creating a new StringBuilder each time.
String is immutable, each time you perform an operation that "changes" it you are creating a new string to replace the old one.
As mentioned above multiple times, that makes the StringBuilder more efficient for operations that manipulate strings.
 
Share this answer
 
Comments
Espen Harlinn 17-Aug-11 18:47pm    
Right, my 5
 
Share this answer
 
Comments
[no name] 26-Mar-14 16:28pm    
There is really no need to answer questions that are years and years old and already have plenty of answers.
 
Share this answer
 
v2
C#
String:
Its a class used to handle strings. String object is used to concatenate two strings. Strings are immutable.Slower

String Builder:

This is also the class used to handle strings.Here Append method is used. String Builder is mutable.Faster [spam link removed]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900