最适合网络开发者的网站
C# 语言。W3Schools 英文课程

尿素 西斯

C# String Interpolation


String Interpolation

Another option of string concatenation is string interpolation, which substitutes values of variables into placeholders in a string. Note that you do not have to worry about spaces, like with concatenation:

例子

string firstName = "John";
string lastName = "Doe";
string name = $"My full name is: {firstName} {lastName}";
Console.WriteLine(name);

亲自尝试 »

Also note that you have to use the dollar sign ($) when using the string interpolation method.

String interpolation was introduced in C# version 6.