Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Whats the use of string builder?

Answer Posted / kishoreg

Since C# strings are immutable, an existing string cannot
be modified. So, if one tries to change a string either
with the concatenation operator (+) or with the Insert,
PadLeft, PadRight, Replace, or SubString methods, an
entirely new string is created—leaving the original string
intact.

Therefore, operations which would alter strings—instead—
cause additional memory to be allocated. Memory is a scarce
resource. And, memory allocations are expensive in terms of
memory and performance. Consequently, sometimes String
class usage should be avoided.

The StringBuilder class is designed for situations when one
needs to work with a single string and make an arbitrary
number of iterative changes to it. Many StringBuilder class
methods are the same as those of the String class. However,
the string content of a StringBuilder class can be changed
without the necessity of allocating additional memory.
Thus, operations on the StringBuilder class will be much
faster than operations on the String class in certain
situations. Paradoxically, just the the opposite can be
true in other situations.

The String class is optimized and quite efficient for most
cases. On the other hand, if strings must be modified, then
the String class can be a real resource waster. It must be
appreciated that the String class is really very
intelligent in its memory handling in most everyday
programming situations.

Instead of the String class, use the StringBuilder class
when a single string must be modified repeatedly.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is serialization and deserialization in c# with example?

853


How a two-dimensional array declared in C#?

917


Explain the serialization in .net

946


You are creating a custom usercontrol, some of the newly created properties are shown in the properties window. How you can hide a new property named theme from the properties window?

882


What does an indexer do?

840


What does .length do in c#?

898


What is firstordefault c#?

901


What is a verbatim string literal and why do we use it?

906


What is a byte in c#?

931


Is c# pass by value?

862


Explain the difference between object type and dynamic type variables in c#?

899


What are the benefits of using the aggregate method in linq?

948


Write a program to create a user control with name and surname as data members and login as method and also the code to call it. (Hint use event delegates) Practical Example of Passing an Events to delegates

848


What is datareader c#?

884


what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?

1844