Using variables inside strings

后端 未结 4 1360
执笔经年
执笔经年 2020-11-27 04:45

In PHP I can do the following:

$name = \'John\';
$var = \"Hello {$name}\";    // => Hello John

Is there a similar language construct in

4条回答
  •  广开言路
    2020-11-27 05:37

    In C# 6 you can use string interpolation:

    string name = "John";
    string result = $"Hello {name}";
    

    The syntax highlighting for this in Visual Studio makes it highly readable and all of the tokens are checked.

提交回复
热议问题