C#字符串和Char一樣,可以包含Unicode、十六進制數轉義序列。因為這些轉義序列以一個“\”(反斜槓)開頭,所以不能在字符串中使用這個非轉義的反斜槓字符,而是需要兩個反斜槓字符("\\")來表示他:
string filepath="c:\\CSharp\\One.cs";
即使我們相信自己可以在任何情況下都記得要這麼做,但寫兩個反斜槓會令人迷惑,幸好,C#提供了另外一種替代方式,可以在字符串變量前面加上字符"@",在“@”後的所有字符都看作是其原來的含義————他們不會被解析為轉義字符:
string <A href="mailto:filepath=@"c:\CSharp\One.cs">filepath=@"c:\CSharp\One.cs";
甚至允許字符串裡包含換行:
string text="I just want to share some movies
which i think is valueable and be worth to have a try,to share the deep affection.";
那麼text的值就是:I just want to share some movies
which i think is valueable and be worth to have a try,to share the deep affection;
不是:I just want to share some movies which i think is valueable and be worth to have a try,to share the deep affection;
摘自:幸福的豬專欄