In a literal string literal, except for two double quotes, all escape characters are interpreted verbatim, so if you need a string of two lines, you must manually write it in two lines:
string example = @"string str = ""forty-two""; char pad = '*';"; Console.WriteLine(example); // string str = "forty-two"; // char pad = '*';
From msdn :
A string literal such as @ "c: \ Foo" is called a shorthand literal string. This basically means: "do not apply any interpretations to until the next quotation mark is reached." So, literally, a string literal can contain a backslash (without doubling them) and even line separators. To get a double quote (") in verbatim literally, you just need to double it, for example. @" My name is "John" "" represents a string. My name is "John". Verbal string literals that contain line separators will also contain a space at the beginning of the line, so I try not to use them in cases where there is empty space questions. They are very convenient for including XML or SQL in your source code, although there is another typical use (which does not need line separators) to indicate the path of the file system .
It is worth noting that this does not affect the string in any way: the string indicated as a text literal is exactly the same as the string indicated as a regular string literal with the corresponding escape. The debugger will sometimes display the string as a verbatim string literal - this is solely for the convenience of viewing the contents of the string, without worrying about escaping.
[Posted by John Skeet]
source share