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

一个人想着一个人 提交于 2019-12-17 06:15:45

问题


How to escape the character \ in C#?


回答1:


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.




回答2:


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];



回答3:


use double backlash like so "\"

"\\"

cause an escape




回答4:


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




回答5:


Escape it: "\\"

or use the verbatim syntax: @"\"




回答6:


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



来源:https://stackoverflow.com/questions/15748040/how-do-i-write-the-escape-char-to-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!