可能重复:
How to escape brackets in a format string in .Net
string.format format string containing {
我正试图格式化这样的字符串,
{enum.enum1,“enum1string”}
我试过这个密码

foreach (KeyValuePair<int, string> p in Helper.Dict)
            {
               // file.WriteLine(string.Format("{0} | {1}",p.Key,p.Value));
               file.WriteLine(string.Format("{Enum.{0},\"{1}\"}", p.Value,p.Value));

            }

但它不起作用。如何以字符串格式添加{。
我正在考虑使用StringBuilder。

最佳答案

从这个MSDN FAQ

string s = String.Format("{{ hello to all }}");
Console.WriteLine(s);    //prints '{ hello to all }'

07-24 09:50
查看更多