How to escape the character \\
in C#?
Double escape it. Escape escape = no escape! \\
Escape it: "\\"
or use the verbatim syntax: @"\"
You just need to escape it:
char c = '\\';
Or you could use the Unicode escape sequence:
char c = '\u005c';
See my article on strings for all the various escape sequences available in string/character literals.
You can escape a backslash using a backslash.
//String
string backslash = "\\";
//Character
char backslash = '\\';
or
You can use the string literal.
string backslash = @"\";
char backslash = @"\"[0];
use double backlash like so "\"
"\\"
cause an escape
If you want to output it in a string, you can write "\\"
or as a character, you can write '\\'
.