This one just caught me by suprise.

  • Thread starter Thread starter web1110
  • Start date Start date
W

web1110

This

Console.WriteLine(@"sl["B"]={0}", sl["B"]);

causes a syntax error.

How do I include the quote (") in a verbatum string? Leave off the @ and
backslash the quotes?
 
web1110 said:
This

Console.WriteLine(@"sl["B"]={0}", sl["B"]);

causes a syntax error.

How do I include the quote (") in a verbatim string? Leave off the @ and
backslash the quotes?

Or I think you can write the quote twice.
 
web1110 said:
This

Console.WriteLine(@"sl["B"]={0}", sl["B"]);

causes a syntax error.

How do I include the quote (") in a verbatum string? Leave off the @ and
backslash the quotes?

Double the quotes:

Console.WriteLine ("sl[""B""]={0}", sl["B"]);

Frankly though, I think it's more readable just to use a normal
literal.
 
Or for readability you could use
string str = string.Format("sl['B']={0}",sl["B"]);
str = str.Replace("'","\"");

web1110 said:
This

Console.WriteLine(@"sl["B"]={0}", sl["B"]);

causes a syntax error.

How do I include the quote (") in a verbatum string? Leave off the @ and
backslash the quotes?

Double the quotes:

Console.WriteLine ("sl[""B""]={0}", sl["B"]);

Frankly though, I think it's more readable just to use a normal
literal.
 
Back
Top