在String中使用括号时:"输入字符串的格式不正确"

Rub*_*zzo 3 c# string string-formatting c#-4.0

如何在C#中格式化字符串,其中模式有括号?当我运行以下声明时......

String.Format("Foo { Bar={0} }", this.Bar);
Run Code Online (Sandbox Code Playgroud)

...我收到运行时异常:

System.FormatException:输入字符串的格式不正确.

我是否应该逃避括号?如何?

Dus*_*gen 14

通过像括号加倍逃离支架{{}}

String.Format("Foo {{ Bar={0} }}", this.Bar);
Run Code Online (Sandbox Code Playgroud)