views:

316

answers:

5

In a literal string (@"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 literal string?

(This understandably doesn't work: string foo = @"this \"word\" is escaped";)

+18  A: 

Use a double quote. ie @"this ""word"" is escaped";

Myles
two double quotes are a quadruple quote xD
fortran
+8  A: 

Use double quotation marks.

string foo = @"this ""word"" is escaped";
Brandon
A: 

It is either

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

or

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

Burt
If you're not sure, why not check before answering?
Iceman
Was just trying to help...
Burt
+3  A: 

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

rfonn
+1  A: 

For adding some more information, your example will work without the @ simbol (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).

j.a.estevan