471,350 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

The @ symbol

hello,

What does the "@" symbol do in the following line of code? I tried
searching the web but searching for "@ and c#" seems to be a waste of
time :)

FileInfo fi = new FileInfo(di.FullName + @"\myxmlfile.xml");

Thanks,
-J

Feb 15 '06 #1
7 1222
>FileInfo fi = new FileInfo(di.FullName + @"\myxmlfile.xml");

It makes it a verbatim string literal where \ isn't treated as an
escape character. It's equivalent to the regular string
"\\myxmlfile.xml".

You may also want to consider calling System.IO.Path.Combine instead
of doing straight string concatenation.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 15 '06 #2
It indicates that the string should be taken as-is: the backslash in
this case is _not_ an escape character. It's meant to make writing
Windows / DOS pathnames easier. Rather than having to write this:

FileInfo fi = new FileInfo(di.FullName + "\\myxmlfile.xml");

so that the \\ resolves into a single \, you can specify no escapes:

FileInfo fi = new FileInfo(di.FullName + @"\myxmlfile.xml");

so here the compiler doesn't attempt to resolve "\m" into a special
character. This can be very handy if you're using UNC names:

string myPath = @"\\unix1\tiffs\product\4x4\M0356A.tif";

instead of (yuck):

string myPath = "\\\\unix1\\tiffs\\product\\4x4\\M0356A.tif";

Feb 15 '06 #3
<kn*********@gmail.com> wrote:
What does the "@" symbol do in the following line of code? I tried
searching the web but searching for "@ and c#" seems to be a waste of
time :)

FileInfo fi = new FileInfo(di.FullName + @"\myxmlfile.xml");


See http://www.pobox.com/~skeet/csharp/s....html#literals

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 15 '06 #4
In addition to what others have said it can also be used on identifiers
to allow language keywords as names. It's not something you see very
often though. For example, a VB.NET developer could decide that the
identifier "sealed" would be a good name for a property not knowing
that it is a keyword in C#. A C# developer using the VB.NET code would
need to qualify it with an @.

Brian

kn*********@gmail.com wrote:
hello,

What does the "@" symbol do in the following line of code? I tried
searching the web but searching for "@ and c#" seems to be a waste of
time :)

FileInfo fi = new FileInfo(di.FullName + @"\myxmlfile.xml");

Thanks,
-J


Feb 15 '06 #5
Thanks for the info :)

Feb 15 '06 #6
Thanks for the info :)

Feb 15 '06 #7
Brian Gideon <br*********@yahoo.com> wrote:
In addition to what others have said it can also be used on identifiers
to allow language keywords as names. It's not something you see very
often though. For example, a VB.NET developer could decide that the
identifier "sealed" would be a good name for a property not knowing
that it is a keyword in C#. A C# developer using the VB.NET code would
need to qualify it with an @.


Of course, anyone following the .NET naming conventions would
automatically avoid all C# keywords because all keywords in C# are in
lower-case, and all non-private members in the .NET naming conventions
are PascalCased :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 15 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Richard | last post: by
reply views Thread by John Graat | last post: by
1 post views Thread by vsp15584 | last post: by
6 posts views Thread by sadegh | last post: by
2 posts views Thread by karinmorena | last post: by
reply views Thread by Ryan Gaffuri | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.