Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the @ sign mean in the following - Class.Field = @"your text here"; - [duplicate]

Tags:

c#

Possible Duplicate:
what does “@” means in c#

What does the sign @ mean in the following:

Class.Field = @"your text here";

I came across this in a piece of code, the compiler does not seem to complain... I've searched around to no avail...

What does the @ mean?

like image 721
unom Avatar asked Oct 07 '10 18:10

unom


2 Answers

It indicates a verbatim string literal. You can use it so escapes aren't treated as such:

string path = "C:\\Documents and Settings\\UserName\\My Documents";

Becomes:

string path = @"C:\Documents and Settings\UserName\My Documents";
like image 147
Justin Niessner Avatar answered Nov 03 '22 02:11

Justin Niessner


You can do something like

@"C:\temp\testfile.txt"

Without @ you would need to do

"C:\\temp\\testfile.txt"

Also it helps you work with other more complicated strings that should represent XML, for example.

Only one thing that you would need to double-write is " itself.

So, @"Tom said ""Hello!""";

like image 44
Andriy Buday Avatar answered Nov 03 '22 01:11

Andriy Buday