溫馨提示×

如何解決String.Format C#中的轉(zhuǎn)義問題

c#
小樊
116
2024-06-24 22:29:24
欄目: 編程語言

在C#中,可以使用雙重大括號來避免轉(zhuǎn)義問題。例如,如果想要在String.Format中輸出大括號{},可以使用{{}}來表示一個大括號。

string output = string.Format("This is a pair of curly braces: {{{}}}", "inner content");
Console.WriteLine(output);

這樣就可以在輸出中得到" This is a pair of curly braces: {inner content}",而不會產(chǎn)生轉(zhuǎn)義問題。

0