您的位置:首页 > 编程语言 > C#

C#中"@"符号的用法

2011-10-26 12:43 375 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: