newb question... string = @"somestring"

M

mp

why do i find samples containing something like
string fileName = @"C:\somefile"

what is the @ symbol doing in there?



I'm wondering if it has to do with why an equality check returns false on
two identical strings(actually a not equal test returns true when it should
return false)

if (doc.Name != fileName)

returns true when doc.Name and fileName are identical in terms of human
reading (it should return false)



thanks

mark
 
M

mp

mp said:
why do i find samples containing something like
string fileName = @"C:\somefile"

what is the @ symbol doing in there?

I'd still like to know the above, but the following was my bad reading
ability...there was a capitalization difference
 
D

Dylan Parry

mp said:
why do i find samples containing something like
string fileName = @"C:\somefile"

what is the @ symbol doing in there?

It's basically there to tell the compiler to treat the string in a
slightly special way because it contains characters that would otherwise
be treated as escape characters. In the above example, it's the "\" that
would have caused the problem if the @ symbol were not present.

The equivalent line without the @ symbol would be:

string fileName = "C:\\somefile"

Notice the extra "\"? This is because on its own, a single backslash
denotes the beginning of an escape sequence, so without the @ symbol
you'd need to double them up.
 
M

mp

Dylan Parry said:
It's basically there to tell the compiler to treat the string in a
slightly special way because it contains characters that would otherwise
be treated as escape characters. In the above example, it's the "\" that
would have caused the problem if the @ symbol were not present.

The equivalent line without the @ symbol would be:

string fileName = "C:\\somefile"

Notice the extra "\"? This is because on its own, a single backslash
denotes the beginning of an escape sequence, so without the @ symbol
you'd need to double them up.

Thanks for the explanation!
mark
 

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

Top