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

后端 未结 6 1918
独厮守ぢ
独厮守ぢ 2020-11-27 22:03

How to escape the character \\ in C#?

相关标签:
6条回答
  • 2020-11-27 22:34

    Double escape it. Escape escape = no escape! \\

    0 讨论(0)
  • 2020-11-27 22:38

    Escape it: "\\"

    or use the verbatim syntax: @"\"

    0 讨论(0)
  • 2020-11-27 22:44

    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.

    0 讨论(0)
  • 2020-11-27 22:48

    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];
    
    0 讨论(0)
  • 2020-11-27 22:51

    use double backlash like so "\"

    "\\"
    

    cause an escape

    0 讨论(0)
  • 2020-11-27 22:56

    If you want to output it in a string, you can write "\\" or as a character, you can write '\\'.

    0 讨论(0)
提交回复
热议问题