Solved

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

Posted on 2004-09-22
5
208 Views
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?

Thanks.

D.
0
Comment
Question by:ds869
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
_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
TAD


@"I am \nTAD" will result in

I am \nTAD

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


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

Expert Comment

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

Expert Comment

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

Author Comment

by:ds869
ID: 12125774
Thanks.

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

D.
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 12132266

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

679 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