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


this "word" is escaped
| improve this answer | |
  • I'm trying to use @Html.Raw() and the quadruple quote breaks my string – JoshYates1980 Sep 26 '14 at 20:35
  • 1
    Can you use it without the string literal? It seems like Html.Raw() would take care of ensuring it's a string for you... – Myles Sep 27 '14 at 17:32
  • 2
    It's also possible to use it in combination with string interpolation: $@"this ""{wordVar}"" is escaped";. – fdelia Jan 30 '18 at 10:02

Use double quotation marks.

string foo = @"this ""word"" is escaped";
| improve this answer | |

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).

| improve this answer | |

This should help clear up any questions you may have: c# literals

Here is a table from the linked content:

enter image description here

| improve this answer | |

Your Answer

