Using variables inside strings
问题 In PHP I can do the following: $name = 'John'; $var = "Hello {$name}"; // => Hello John Is there a similar language construct in C#? I know there is String.Format(); but I want to know if it can be done without calling a function/method on the string. 回答1: 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. 回答2: This functionality is not