Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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

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
ds869
Asked:
ds869
  • 2
  • 2
1 Solution
 
_TAD_Commented:

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
 
praneethaCommented:
i guess may be it tells that it is not any string.....and it is a path
0
 
praneethaCommented:
well may be TAD is right...sorry saw it after the refresh
0
 
ds869Author Commented:
Thanks.

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

D.
0
 
_TAD_Commented:

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now