Odd string declaration

  • Thread starter Thread starter dotNEWBIE
  • Start date Start date
D

dotNEWBIE

Sorry this a little bit of an odd question but I keep seeing things like
this:

string MyString
myString = @"myinitialstring"


Why the ampersand and not just,


myString = @"myinitialstring"
 
Hi,

the @ is used to tell the compiler to do not parse special characters.

You can write:

str = @"c:\" instead of str = "c:\\"
or
str = @"SELECT id
FROM xxx"

instead of
str = "SELECT id" +
"FROM xxx"


Santiago Corredoira
www.syltek.com
 
It doesn't negate them so much as make them unnecessary. On the other
hand, you can't use escapes to include special characters in your
string.

Very handy for DOS file paths, which are full of backslashes.
 
Back
Top