Alex Rivera | Logout

C# '@' before a String

Asked 2011-02-02T19:53:17.963
153

Possible Duplicate:
What's the @ in front of a string for .NET?

I found this in a C# study book

DirectoryInfo dir = new DirectoryInfo(key.Key.ToString() + @":\");

The book however did not explain what the '@' symbol was for. I tried searching MSDN C# Operators but its not listed there. I can guess that it allows the developer to not have to escape a '\' or does it allow to not have any escape sequences?

What is this for and why would I use @":\" instead of ":\\"?

Thanks for the help

Edit: See the comment below for a similar question

Edit
Report

2 Answers

88

It also means you can use reserved words as variable names.

Say you want a class named class. Since class is a reserved word, you can instead call your class class:

IList<Student> @class = new List<Student>();
answered 2011-02-02T19:56:57.623
2

What is this for and why would I use @":\" instead of ":\"?

Because when you have a long string with many \ you don't need to escape them all and the \n, \r and \f won't work too.

answered 2011-02-02T19:55:29.390

Your Answer