Return to Snippet

Revision: 66585
at May 30, 2014 05:39 by zeke


Initial Code
// This example concatenates using StringBuilder object then writes contents of the 
// StringBuilder object out to a file using streamwriter

StringBuilder textSB = new StringBuilder();
string newLine;

for(int i = 0; i < 50; i++)
{
	newLine = "Line # " + i;
	textSB.Append(newLine).Append("|").Append("\r\n");
}

string filePath = @"c:\output.txt";
using (StreamWriter outFile = new StreamWriter(filePath))
    outFile.Write(textSB.ToString());

Initial URL

                                

Initial Description
StringBuilder class is a much better way to concatenate strings.  Unlike a string object it can be changed as needed, and is much more efficient than using +=

Initial Title
C#: Using StringBuilder for Concatnation

Initial Tags
c#

Initial Language
C#