preety
preety

Reputation: 1066

What does string builder do?

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

Upvotes: 1

Views: 1787

Answers (3)

Oded
Oded

Reputation: 499252

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.

Upvotes: 7

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55509

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

Upvotes: 1

Hans Kesting
Hans Kesting

Reputation: 39339

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();

Upvotes: 6

Related Questions