Pages

Ads 468x60px

For New Update Use this Link http://dotnethubs.blogspot.in/ Offer for you

.

Showing posts with label string vs stringbuilder asp.net. Show all posts
Showing posts with label string vs stringbuilder asp.net. Show all posts

Monday 1 April 2013

Simple difference between String and StringBuilder asp.net

Simple difference between String and StringBuilder asp.net

Simple difference between String and StringBuilder asp.net

The main difference beween string and stringbuilder is that when we are copying two string in the case of string concatination is done means that one string is attached to another string and attaced string is deleted, and one new memory allocation is done.it takes lot of time and this is time taking process.


but in case of stringbuilder copying two stings means string1 is appended to string2 or vice versa.no memory allocation and deletion of string.So it is very efficient process and it takes less time.

Difference Between String and String
String


1.Its a class used to handle strings.
2.Here concatenation is used to combine two strings.
3.String object is used to concatenate two strings.
4.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
5.That is why  "Strings are immutable".
6. Slower

String Builder
1.This is also the class used to handle strings.
2.Here Append method is used.
3.Here, Stringbuilder object is used.
4.Insertion is done on the existing string.
5.Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed.
6. Faster

class
Program{static void Main(string[] args){
//for example:

string str = "hello"; //Creates a new object when we concatenate any other words along with str variable it does not actually modify the str variable, instead it creates a whole new string.
str = str + " to all";Console.WriteLine(str);StringBuilder s = new StringBuilder("Hi");s.Append(" To All");Console.WriteLine(s);Console.Read();}
}
 

..




New Updates

Related Posts Plugin for WordPress, Blogger...

Related Result