在C#中,在Console.WriteLine中使用美元符号做什么

TJ *_*rey 3 console.writeline c#-6.0

感谢您查看我的问题,以验证我的意思

Console.WriteLine($"Hello {variable}");
Run Code Online (Sandbox Code Playgroud)

我很好奇$对Console.WriteLine输出的影响

小智 8

Console.WriteLine($"Hello {variable}");
Run Code Online (Sandbox Code Playgroud)

我认为等于:

Console.WriteLine(string.Format("Hello {0}", variable));
Run Code Online (Sandbox Code Playgroud)

就像将其格式化一样,它只是将参数移到索引位置。


Tha*_*ina 5

这是一个新功能,除了 string.Format

它被称为内插字符串