<分区>
如何在 C# 中格式化模式中包含方括号的字符串?当我运行以下语句时...
String.Format("Foo { Bar={0} }", this.Bar);
...我收到一个运行时异常:
System.FormatException: Input string was not in a correct format.
我应该转义括号吗?怎么办?
<分区>
如何在 C# 中格式化模式中包含方括号的字符串?当我运行以下语句时...
String.Format("Foo { Bar={0} }", this.Bar);
...我收到一个运行时异常:
System.FormatException: Input string was not in a correct format.
我应该转义括号吗?怎么办?
最佳答案
通过加倍括号来转义括号,例如 {{
和 }}
String.Format("Foo {{ Bar={0} }}", this.Bar);
关于c# - 在字符串 : "Input string was not in a correct format" 中使用括号时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14856648/