Solved

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

Posted on 2004-09-22
5
205 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now