根据文档:
插值字符串的结构如下:
{ <interpolationexpression>[,<alignment>][:<formatString>] }
问题在于冒号用于表示格式,例如:
Console.WriteLine($"The current hour is {hours:hh}")解决方案是 将 条件 包装 在括号中:
var result = $"Descending {(isDescending ? "yes" : "no")}";
根据文档:
插值字符串的结构如下:
{ <interpolationexpression>[,<alignment>][:<formatString>] }
问题在于冒号用于表示格式,例如:
Console.WriteLine($"The current hour is {hours:hh}")解决方案是 将 条件 包装 在括号中:
var result = $"Descending {(isDescending ? "yes" : "no")}";