<分区>
如何在使用 String.Format 方法时显示文字花括号字符?
例子:
sb.AppendLine(String.Format("public {0} {1} { get; private set; }",
prop.Type, prop.Name));
我希望输出看起来像这样:
public Int32 MyProperty { get; private set; }
<分区>
如何在使用 String.Format 方法时显示文字花括号字符?
例子:
sb.AppendLine(String.Format("public {0} {1} { get; private set; }",
prop.Type, prop.Name));
我希望输出看起来像这样:
public Int32 MyProperty { get; private set; }
最佳答案
使用双括号 {{
或 }}
使您的代码变为:
sb.AppendLine(String.Format("public {0} {1} {{ get; private set; }}",
prop.Type, prop.Name));
// For prop.Type of "Foo" and prop.Name of "Bar", the result would be:
// public Foo Bar { get; private set; }
关于c# - 在 String.Format 中转义大括号 '{',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3773857/