csharp StringBuilder

StringBuilder sb = new StringBuilder();
int totalNumbers = 7;

sb.Append("Looping through " + totalNumbers.ToString());
sb.AppendLine(" Numbers:");

for (int i = 1; i <= totalNumbers; i++)
{
	sb.AppendFormat("Number: {0}, Remaining: {1}\n", i.ToString(), (totalNumbers - i).ToString());
}

sb.Append("End of StringBuilder").AppendLine();

Console.WriteLine(sb.ToString());

//output as below:
/*
	Looping through 7 Numbers:
	Number: 1, Remaining: 6
	Number: 2, Remaining: 5
	Number: 3, Remaining: 4
	Number: 4, Remaining: 3
	Number: 5, Remaining: 2
	Number: 6, Remaining: 1
	Number: 7, Remaining: 0
	End of StringBuilder

*/
Example use for System.Text.StringBuilder

Updated: Saturday 9th October 2010, 07:36pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.