Can I escape a double quote in a verbatim string literal?

In a verbatim string literal (@"foo") in C#, backslashes aren't treated as escapes, so doing " to get a double quote doesn't work. Is there any way to get a double quote in a verbatim string literal?

This understandably doesn't work:

string foo = @"this "word" is escaped";

Use a duplicated double quote.

@"this ""word"" is escaped";

outputs:

this "word" is escaped

使用双引号。

string foo = @"this ""word"" is escaped";

For adding some more information, your example will work without the @ symbol (it prevents escaping with ), this way:

string foo = "this "word" is escaped!";

It will work both ways but I prefer the double-quote style for it to be easier working, for example, with filenames (with lots of in the string).

链接地址: http://www.djcxy.com/p/93644.html

上一篇: 何时在MySQL中使用单引号,双引号和反标号

下一篇: 我可以在逐字字符串文字中转义双引号吗?