Wednesday, March 28, 2012

What is the @ for?

I have see code example such as this one

Directory.CreateDirectory(@dotnet.itags.org."\\machine\share");

What is that @dotnet.itags.org. for? What does it do?When you use @., escape sequences in string are not evaluated.

For example:


@."c:\Docs\Source\a.txt" // rather than "c:\\Docs\\Source\\a.txt"

Here is about @. in the docs.

Directory.CreateDirectory(@."\\machine\share");
is equivalent to:
Directory.CreateDirectory("\\\\machine\\share");
Just as this
string myString = @."
a'b c d e
f""g";
is equivalent to:
string myString = "\na\'b c d e\nf\"g";
Just as he said, it helps to avoid escaping characters.

0 comments:

Post a Comment