@ tells C # to treat this as a literal string literal string literal . For example:
string s = "C:\Windows\Myfile.txt";
is a mistake because \W and \M are not valid escape sequences. You should write it like this:
string s = "C:\\Windows\\Myfile.txt";
To make it more understandable, you can use a literal string that does not recognize \ as a special character. Consequently:
string s = @"C:\Windows\Myfile.txt";
fine.
EDIT: MSDN provides the following examples:
string a = "hello, world"; // hello, world string b = @"hello, world"; // hello, world string c = "hello \t world"; // hello world string d = @"hello \t world"; // hello \t world string e = "Joe said \"Hello\" to me"; // Joe said "Hello" to me string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me string g = "\\\\server\\share\\file.txt"; // \\server\share\file.txt string h = @"\\server\share\file.txt"; // \\server\share\file.txt string i = "one\r\ntwo\r\nthree"; string j = @"one two three";
Billy oneal
source share