Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

CSharp @

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 17 Apr 2008 14:17 GMT
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
Leon Mayne - 17 Apr 2008 14:26 GMT
> Hi,
>
[quoted text clipped - 10 lines]
>
> FileInfo myFile = new FileInfo("c:\Temp\Test\readme.txt"); ?

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

FileInfo myFile = new FileInfo("c:\\Temp\\Test\\readme.txt");
David - 17 Apr 2008 14:29 GMT
S'ok- found out.

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

> Hi,
>
[quoted text clipped - 14 lines]
>
> David
Mark Rae [MVP] - 17 Apr 2008 14:44 GMT
> What's the @ symbol for before a string?

http://www.c-sharpcorner.com/UploadFile/harishankar2005/verbatim_literals1126200
5010742AM/verbatim_literals.aspx


Signature

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

Cowboy (Gregory A. Beamer) - 17 Apr 2008 16:49 GMT
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.

Signature

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!

*************************************************
> Hi,
>
[quoted text clipped - 14 lines]
>
> David

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.