• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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