C# 6中有一个新特性:插值字符串。这使您可以直接将表达式放入代码中。
与依赖索引不同:
string s = string.Format("Adding \"{0}\" and {1} to foobar.", x, this.Y());
以上变为:
string s = $"Adding \"{x}\" and {this.Y()} to foobar.";
但是,我们有很多跨越多行的字符串使用verbatim字符串(主要是SQL语句),像这样:
string s = string.Format(@"Result...
Adding ""{0}"" and {1} to foobar:
{2}", x, this.Y(), x.GetLog());
将它们恢复为常规字符串似乎有些凌乱:
string s = "Result...\r\n" +
$"Adding \"{x}\" and {this.Y()} to foobar:\r\n" +
x.GetLog().ToString();
如何同时使用verbatim字符串和插值字符串?