string.Format抛出异常

ama*_*eur 2 .net c# string

我有一个String.Format的问题,我需要帮助:

string Placeholder = @"(function({0}, $, undefined) { {1} }( window.{0} = window.{0} || {}, jQuery));";
string output = string.Format(Placeholder, "Value1", "Value2");
Run Code Online (Sandbox Code Playgroud)

String.Format上有以下异常

'string.Format(占位符,"Value1","Value2")'引发了类型'System.FormatException'字符串{System.FormatException}的异常

知道为什么吗?

Ry-*_*Ry- 9

这是因为括号:{ {1} }|| {}.使用双打:

string Placeholder = @"(function({0}, $, undefined) {{ {1} }}( window.{0} = window.{0} || {{}}, jQuery));";
string output = string.Format(Placeholder, "Value1", "Value2");

http://geekswithblogs.net/jonasb/archive/2007/03/05/108023.aspx