Possible Duplicate:
What's the @ in front of a string for .NET?
I have the following code:
new Attachment(Request.PhysicalApplicationPath + @"pdf\" + pdfItem.Value)
What does the @ sign do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It has nothing to do with filepath. It changes the escaping behavior of strings.
In a string literal prefixed with
@the escape sequences starting with\are disabled. This is convenient for filepaths since\is the path separator and you don’t want it to start an escape sequence.In a normal string you would have to escape
\into\\so your example would look like this “pdf\\”. But since it’s prefixed with@the only character that needs escaping is"(which is escaped as"") and the\can simply appear.This feature is convenient for strings literals containing
\such as filepaths or regexes.For your simple example the gain isn’t that big, but image you have a full path
"C:\\ABC\\CDE\\DEF"then@"C:\ABC\CDE\DEF"looks a lot nicer.For regular expressions it’s almost a must. A regex typically contains several
\escaping other characters already and often becomes almost unreadable if you need to escape them.