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;
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;
相关文章推荐
- Post 与 Get 用法不一样 "&"符号
- 学习笔记:shell 下 符号 [`],[""], [''], [$] 用法
- C语言中宏定义"#"和"##"符号的用法
- 使用CryptoAPI获取证书扩展属性之二:“密钥用法”和"增强型密钥用法"
- qt中 ".pro" 文件的用法
- extern "c"的用法
- 为什么会出现LNK2005"符号已定义"的链接错误?
- extern "C"的用法解析
- 宏中"#"和"##"的用法
- Oracle 中"=" 和 "<>" 的用法
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- 当OpenCV编译遇到"无法解析的外部符号"时(编译peopledetect.cpp)
- 如何打印符号"/"
- 解决:VS2008 右键点击"转到定义"出现"未定义符号" 和 类视图不能显示全部的类型
- extern "C"的用法解析
- c语言 宏操作,宏中"#"和"##"的用法,中间转换宏
- extern "C"的用法解析
- 错误 error LNK2019: 无法解析的外部符号 "void __cdecl ........的解决
- 宏中"#"和"##"的用法
- Qt 出现了 Qt error LNK2019: 无法解析的外部符号 "public: __thiscall 怎么解决