Newbie Q.: what is @?

  • Thread starter Thread starter B. Cavour
  • Start date Start date
B

B. Cavour

In a statement such as this:

public static string mySQLStatement = @"SELECT * FROM MY_TABLE";

what does the "@" before the string mean?



--B. Cavour.
 
It means that string following the '@' is interpreted literally, so you
don't have to use character escapes. For example,

@"c:\temp\foo.txt"

is identical to

"c:\\temp\\foo.txt"

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
B. Cavour said:
In a statement such as this:

public static string mySQLStatement = @"SELECT * FROM MY_TABLE";

what does the "@" before the string mean?



--B. Cavour.


I'm pretty sure that it tells the compiler to ignore escape sequences, I use
it for a path;
string path = @"C:\temp\";

Where normally I would need to use esacpe characters to accomplish the same;
string path = "C:\\temp\\";

I'm sure there is a better explanation than that, I'm just trying to give
back a little ;0)
 
In a statement such as this:
public static string mySQLStatement = @"SELECT * FROM MY_TABLE";

what does the "@" before the string mean?

It specifies a verbatim string literal. basically it disables \ as an
escape character.

"c:\\foo" == @"c:\foo"

In the SQL example above it's not needed and makes no difference.


Mattias
 
Ahhh!

Thanks to everyone who responded :)

Mattias Sjögren said:
It specifies a verbatim string literal. basically it disables \ as an
escape character.

"c:\\foo" == @"c:\foo"

In the SQL example above it's not needed and makes no difference.


Mattias
 
It also means that the string can be mullti-line in the .cs file.

e.g.:

string s = @"

";

-KJ
 
Back
Top