What does the @ mean in front of a variable name or literal string in C#?

Posted on 2004-09-22
Last Modified: 2010-04-15
I saw it a lot but just don't know what the @ is inside a C# file. I am not talking about directives, but the @ before a variable, like:

string path = @"c:\temp\MyTest.txt";

Is it something about reference?


Question by:ds869
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 22

Accepted Solution

_TAD_ earned 50 total points
ID: 12125650

it means that the compiler takes the string as a string literal.

That is, in C# the \ is an escape character.

"I am \nTAD" will result in

I am

@"I am \nTAD" will result in

I am \nTAD

\t - tab
\n - new line
\' = '
\" = "
\\ - \

google "C# escape characters" for more info
LVL 15

Expert Comment

ID: 12125655
i guess may be it tells that it is not any string.....and it is a path
LVL 15

Expert Comment

ID: 12125667
well may be TAD is right...sorry saw it after the refresh

Author Comment

ID: 12125774

So does C# accept path with '/' like 'c:/mydir/' or I have to use @'c:\mydir\'?

LVL 22

Expert Comment

ID: 12132266

C# DOES accept C:/temp/stuff as a valid path

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question