string builder in c# ?

Posted by Vivekjj under C# on 11/19/2012 | Points: 10 | Views : 1201 | Status : [Member] | Replies : 4
why we go for stringbuilder? wat is the use of it?




Responses

Posted by: Sandhyab on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
A String Builder can be changed as many times as necessary. It yields astonishing performance improvements. It eliminates millions of string copies. And in certain loops it is essential.
Example :
StringBuilder builder = new StringBuilder();


for (int i = 0; i < 10; i++)
{
builder.Append(i).Append(" ");
}
Response.WriteLine(builder);

Output:
0 1 2 3 4 5 6 7 8 9
Above program shows how the StringBuilder type is used to build up a larger buffer of characters. You can call the Append method on the StringBuilder instance to add more and more data.

Vivekjj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 11/19/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Once created string will not able to change but string builder we can change ,
but initialization of string builder will effect on the performance .
Usage:
Declaring Once and adding the strings to it, in this scenario it will be useful for us

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Vivekjj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Krv on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
StringBuilder is designed to allow you to pre-allocate some memory and then assign characters to it. StringBuilder will monitor the usuage of the memory buffer and if it needs more it will automatically re-allocate

Thanks,
R.Vasanth
MCTS(SQL Server & BI)
http://bigdatatech.blogspot.com

Vivekjj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravya on: 11/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi..
Instead of Using String...Most of people Use the StringBuilder..
Why Becoz, Once created a string cannot be changed,A StringBuilder can be changed as many times as necessary and Improves the Performance and
It eliminates millions of string copies. And in certain loops it is essential.

for more Information Go through this below link..
http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-using-stringbuilder

With Regards,
sravya

Vivekjj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response