这是一个针对 C#(或可能是 VB)的 .NET 问题,但我试图找出以下声明之间的区别:
This is a .NET question for C# (or possibly VB), but I am trying to figure out what's the difference between the following declarations:
string hello = "hello";对比
string hello_alias = @"hello";在控制台打印出来没有区别,长度属性是一样的.
Printing out on the console makes no difference, the length properties are the same.
推荐答案它将字符串标记为 逐字字符串文字 - 字符串中通常被解释为转义序列的任何内容被忽略.
It marks the string as a verbatim string literal - anything in the string that would normally be interpreted as an escape sequence is ignored.
所以 "C:\Users\Rich" 和 @"C:UsersRich"
有一个例外:双引号需要转义序列.要转义双引号,您需要连续放置两个双引号.例如,@"""" 的计算结果为 ".
There is one exception: an escape sequence is needed for the double quote. To escape a double quote, you need to put two double quotes in a row. For instance, @"""" evaluates to ".
更多推荐
C#中字符串前面的@是什么?
发布评论