星期二, 9月 06, 2005

[.Net]'@' in c# string literal

為什麼網路上很多範例都會在字串前面加上 '@' 呢??
幸好有c# specification, 這才解答了我的疑惑...
c# specification裡面對此有相當多的描述,但是看下面的範例,應該會很容易瞭解.

string a = "Happy birthday, Joel"; // Happy birthday, Joel
string b = @"Happy birthday, Joel"; // Happy birthday, Joel
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";

沒有留言: