是否可以将 {....} 与 string.Format 一起使用?
var test = "{value: {0}}";
Console.WriteLine(string.Format(test, 10));
System.FormatException: Input string was not in a correct format.
最佳答案
转义 {
和 }
的方法是复制它们:
var test = "{{value: {0}}}";
将打印{value: 10}
文档是 here ,并且还列出了一个有用的替代方案:
string.Format("{0}{1:D}{2}", "{", value, "}");
关于c# - 是否可以在大括号内使用占位符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55206759/