Thursday, July 9, 2009

How do I define an string in C# that has a " in it?

In Vb I would just use """hi""" but that ain't working...

How do I define an string in C# that has a " in it?
You can use the backslash escape method OR you can also use the @-quoted string literal. This saves from having to escape anything except double quotes:





@"""Ahoy!"" cried the captain."





Would print out as:





"Ahoy!" cried the captain.
Reply:If C# is anything like Java *cough cough*, then write it like this: "\"hi\"". The backslash works as an escape. Javascript works the same way...


No comments:

Post a Comment