考虑:
string newline = "\r\n";
Console.WriteLine($"Hello without at{newline}how are you?");
Console.WriteLine($"Hello with at{@newline}how are you?");
这两行代码的输出结果是相同的。换行符总是被打印成一个新的一行。
Hello without at
how are you?
Hello with at
how are you?
那么我何时需要在大括号中使用“@”符号?
@
,通常与关键字一起使用,例如在扩展方法中将@this
作为第一个参数的名称。 - Jon Skeet@
,但你可以使用带或不带@
的这个变量。 - Tim Schmelter