Why the @ ?

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

In my sample program I have the following:

File.Create(@"c:\newfile.zip")

Why does it use an @ sign?

I don't normally have to do that in my code to open a file.

Thanks,

Tom
 
@ is escape indcator..

File.Create(@"c:\newfile.zip")
or
File.Create("c:\\newfile.zip")

VJ
 
Mark Rae said:
No it isn't - @ indicates that what follows it is a string literal...

More importantly, a verbatim string literal. Just "hello" is a string
literal.
 
In my sample program I have the following:

File.Create(@"c:\newfile.zip")

Why does it use an @ sign?

I don't normally have to do that in my code to open a file.

Thanks,

Tom
Look carefully at your string, it has "\n" in it, which is normally a
newline character. The @ indicates that the string is to be
interpreted literally, without any of the special characters such as
\n, \t etc.

Alternatives are :

File.Create("c:\\newfile.zip")

or

File.Create("c:/newfile.zip")

The first alternative escapes the '\', the second makes use of the
fact that Windows recognises Unix-style filenames with '/' instead of
'\'.

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top