The String object is immutable.
A string requires a new allocation of space for every new object.
In situations where you need to perform repeated modifications to a string,a new String object can be costly.
The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object.
using System;
using System.Text;
namespace forgetCode
{
class program
{
public static void Main()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Forget Code");
sb.AppendLine("works");
sb.AppendLine("nicely");
Console.Write(sb.ToString());
}
}
}
Output:
Forget Code
works
nicely