How to use verbatim strings with interpolation?

前端 未结 1 345
攒了一身酷
攒了一身酷 2020-12-05 03:55

In C# 6 there is a new feature: interpolated strings. These let you put expressions directly into code.

Rather than relying on indexes:

string s = stri         


        
1条回答
  •  不思量自难忘°
    2020-12-05 04:07

    You can apply both $ and @ prefixes to the same string:

    string s = $@"Result...
    Adding ""{x}"" and {this.Y()} to foobar:
    {x.GetLog()}";
    

    Since being introduced in C# 6, interpolated verbatim strings had to start with the tokens $@, but starting with C# 8, you can use either $@ or @$.

    0 讨论(0)
提交回复
热议问题