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";
上面是msdn給的例子,說明了加不加@的差別,
基本上加上@就是告訴編譯器,接下來的這個字串我會全權負責,請編譯器不要自做聰明,只要如實照做就好了
如果你不加@,只要有反斜線,編譯器會以跳脫字元去解讀,比如像\t,就是按一次tab鍵的意思.
而使用@要注意的是上例的string f,我如果要顯示"時,要用""來取代.