Solved

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

Posted on 2004-09-22
5
215 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
[X]
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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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