Looking for c# Answers? Try Ask4KnowledgeBase
Looking for c# Keywords? Try Ask4Keywords

C# Language字符串插值


句法

  • $“content {expression} content”
  • $“content {expression:format} content”
  • $“content {expression} {{braces中的內容}}內容}”
  • $“content {expression:format} {{content in braces}} content}”

備註

字符串插值是string.Format()方法的簡寫,它使得更容易構建具有變量和表達式值的字符串。

var name = "World";
var oldWay = string.Format("Hello, {0}!", name);  // returns "Hello, World"
var newWay = $"Hello, {name}!";                   // returns "Hello, World"

字符串插值 相關例子