What is the Main difference between String and
StringBuilder and why do we use StringBuilder.
Answer Posted / wavare santosh
What is the difference between String and StringBuilder?
Both String and StringBuilder are classes used to handle
strings.
The most common operation with a string is concatenation.
This activity has to be performed very efficiently. When we
use the "String" object to concatenate two strings, the
first string is combined to the other string by creating a
new copy in the memory as a string object, and then the old
string is deleted. This process is a little long. Hence we
say "Strings are immutable".
When we make use of the "StringBuilder" object, the Append
method is used. This means, an insertion is done on the
existing string. Operation on StringBuilder object is
faster than String operations, as the copy is done to the
same location. Usage of StringBuilder is more efficient in
case large amounts of string manipulations have to be
performed.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How do you prevent a method from being overridden in c#?
How to parse a date time string?
Is comparable a functional interface?
Why is it efficient to use System.string under System.Text.StringBuilder ?
What are get and set in c#?
What is enum in c#?
What is clr in c#?
How many types of collections are there in c#?
Why do we override in c#?
How will you get the different language strings?
What is a int in c#?
How assembly versioning in .NET prevent DLL Hell problem?
What is the default value of decimal in c#?
Is c# slower than java?
Differentiate between dataset and datareader?