Skip to content
Justice Tech School

C# StringBuilder and Escapes

Joining many strings in a loop is slow, so use StringBuilder. Escape sequences include \n, \t and \". Verbatim strings with @ keep backslashes, and raw strings use triple quotes.

Example
using System.Text;
var sb = new StringBuilder();
for (int i = 1; i <= 3; i++) sb.Append(i).Append(',');
Console.WriteLine(sb.ToString());
Console.WriteLine(@"C:\temp\file.txt");

Exercise

Build a string efficiently.

new ()

Quiz Test

Why use StringBuilder?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.