@"verbatim strings are strings whose contents are not escaped, so in this case \n does not represent the newline character but two individual characters: \ and n. Verbatim strings are created prefixing the string contents with the @ character"
@"To escape quotation marks, ""double quotation marks"" are used."
To concatenate string literals, use the @ symbol at the beginning of each string.
Escaping Double Quotes
Double Quotes inside verbatim strings can be escaped by using 2 sequential double quotes
"" to represent one double quote
" in the resulting string.
"I don't think so," he said.
Interpolated Verbatim Strings
Verbatim strings can be combined with the new String interpolation features found in C#6.
Testing \n 1 2 3
As expected from a verbatim string, the backslashes are ignored as escape characters. And as expected from an interpolated string, any expression inside curly braces is evaluated before being inserted into the string at that position.
This is a
Multi-line strings that contain double-quotes can also be escaped just as they were on a single line, because they are verbatim strings.
It should be noted that the spaces/tabulations at the start of lines 2 and 3 here are actually present in the value of the variable; check this question for possible solutions.
Verbatim strings instruct the compiler to not use character escapes
In a normal string, the backslash character is the escape character, which instructs the compiler to look at the next character(s) to determine the actual character in the string. (Full list of character escapes)
In verbatim strings, there are no character escapes (except for
"" which is turned into a
To use a verbatim string, just prepend a
@ before the starting quotes.
This verbatim string
As opposed to using an ordinary (non-verbatim) string:
that will output:
using character escaping. (The
\t is replaced with a tab character and the
\n is replace with a newline.)