String escape sequences are transformed to the corresponding character at compile time. Ordinary strings that happen to contain backwards slashes are not transformed.
For example, the strings notEscaped
and notEscaped2
below are not transformed to a newline character, but will stay as two different characters ('\'
and 'n'
).
string escaped = "\n";
string notEscaped = "\\" + "n";
string notEscaped2 = "\\n";
Console.WriteLine(escaped.Length); // 1
Console.WriteLine(notEscaped.Length); // 2
Console.WriteLine(notEscaped2.Length); // 2