Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CSharp @

0 views
Skip to first unread message

David

unread,
Apr 17, 2008, 9:17:55 AM4/17/08
to
Hi,

I know this isn't a C# group, but its just a quick one.

As a seasoned C++ developer I'm learning C# as I go along. What's the @
symbol for before a string?

eg:

FileInfo myFile = new FileInfo(@"c:\Temp\Test\readme.txt");

Why can't it just be:

FileInfo myFile = new FileInfo("c:\Temp\Test\readme.txt"); ?

Thanks

David

David

unread,
Apr 17, 2008, 9:29:56 AM4/17/08
to
S'ok- found out.

Its for treating the '\' marks as '\' marks, not leading characters.

Leon Mayne

unread,
Apr 17, 2008, 9:26:08 AM4/17/08
to
"David" <a...@asd.com> wrote in message
news:guWdnfIZ3tO...@brightview.com...

Because it escapes all the characters in the string. It couldn't be the
second example you gave, it would have to be:

Mark Rae [MVP]

unread,
Apr 17, 2008, 9:44:25 AM4/17/08
to
"David" <a...@asd.com> wrote in message
news:guWdnfIZ3tO...@brightview.com...

> What's the @ symbol for before a string?

http://www.c-sharpcorner.com/UploadFile/harishankar2005/verbatim_literals11262005010742AM/verbatim_literals.aspx


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Cowboy (Gregory A. Beamer)

unread,
Apr 17, 2008, 11:49:44 AM4/17/08
to
It states the string is a literal, warts and all. Without the @, you are
accepting \ as an escape character.

Your second string would fail, as it is not escaping anything valid.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************


"David" <a...@asd.com> wrote in message
news:guWdnfIZ3tO...@brightview.com...

0 new messages