Concatenating strings using StringBuilder in C#

When performance is important, you should always use the StringBuilder class to concatenate strings.
The following code uses the Append method of the StringBuilder class to concatenate strings without the chaining effect of the + operator.

using System;
using System.IO;
using System.Text;

namespace forgetCode
{
    class program1
    {
        static void Main(string[] args)
        {
            
            // Use StringBuilder for concatenation in tight loops.
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 10; i++)
            {
                sb.AppendLine(i.ToString());
            }
            System.Console.WriteLine(sb.ToString());

            // Keep the console window open in debug mode.
            System.Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();


        }
   
    }
}


Output:
0
1
2
3
4
5
6
7
8
9

..