In a verbatim string (a string starting with @""
) to escape double quotes you use double quotes, e.g. @"Please press ""Ok""."
. If you want to do it with verbatim strings then you would do something like @"\"""
(that's 3 double quotes on the end there).
In verbatim string literals (@"..."
) a "
in the string value is encoded as ""
, which happens to also be the only escape sequence in verbatim strings.
@"\""Happy coding!\""" // => \"Happy coding!\"
"\\\"Happy coding!\\\"" // => \"Happy coding!\"
Note that in the 2nd case (not a verbatim string literal), a \
is required before the \
and the "
to escape them and prevent their normal meanings.
See the C# string reference for more details and examples.
单纯的字符串的话,直接加\进行转义。但是在@开头的字符串中,使用""来表示"