Search code examples
c#escaping

How do I write the escape char '\' to code


How to escape the character \ in C#?


Solution

  • 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.