views:

128

answers:

4

what string builder command do in the asp.net cs file.

+7  A: 

It is not a command - it is a class which is part of the Base Class Library, in the System.Text namespace.

The StringBuilder class lets you construct large strings in an efficient manner.

There is a Microsoft artical titled "Using the StringBuilder Class" that explains how to use this class.

Oded
+6  A: 

It's a way to build strings that doesn't create lots of intermediate strings (that then need to be cleaned up by th GC).

Example code (don't do this):

string s = "";
for (int i=0; i<10000; i++)
   s += "test";

Every time you add something to a string, you create a new string. The old version is discarded and needs to be collected by the GarbageCollector.

Stringbuilder version:

StringBuilder sb = new StringBuilder();
for (int i=0; i<10000; i++)
{   sb.Append("test"); }
string s = sb.ToString();
Hans Kesting
A: 

I'm not sure anyone can explain it better than these guys:

StringBuilder documentation on MSDN

Dave
+1  A: 

StringBuilder is a class available in .net framework.

http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx

For using StringBuilder you can check this link -

http://msdn.microsoft.com/en-us/library/2839d5h5(VS.71).aspx

Sachin Shanbhag