Click here to Skip to main content
11,641,668 members (49,183 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
What is the difference between string and stringbuilder c#?
Posted 17-Aug-11 8:25am
Edited 17-Aug-11 9:14am
Tarun.K.S42.1K
v2
Comments
Tarun.K.S at 17-Aug-11 15:14pm
   
Just one "?" is enough. Stop putting multiple ????.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Espen Harlinn at 17-Aug-11 18:48pm
   
Right, my 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
Espen Harlinn at 17-Aug-11 18:47pm
   
Right, my 5 :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This article goes a bit more into the details than the note posted at dotnetuncle
String Vs StringBuilder (C#)[^]
  Permalink  
Comments
Abhinav1986 at 29-Oct-13 6:17am
   
sss
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
Comments
Espen Harlinn at 17-Aug-11 18:50pm
   
Nice article, my 5
Mohammad A Rahman at 17-Aug-11 19:34pm
   
Thanks Espen :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Comments
Espen Harlinn at 17-Aug-11 18:47pm
   
Right, my 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

  Permalink  
Comments
InsertCleverUserName at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Please try the following URL,

http://onlydifferencefaqs.blogspot.in/2012/08/oops-difference-faqs-4.html[^]

to know the difference between string and stringbuilder in c# with examples
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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]
  Permalink  
v2

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

  Print Answers RSS
0 Mika Wendelius 310
1 DamithSL 213
2 Afzaal Ahmad Zeeshan 139
3 CPallini 134
4 OriginalGriff 120
0 Mika Wendelius 460
1 OriginalGriff 215
2 DamithSL 213
3 CPallini 169
4 Afzaal Ahmad Zeeshan 129


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 26 Mar 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100