How to ignore braces in the string.Format function?
Example:

string.Format("{Name:{0}}", "Value"); 

As a result of this code, we get an exception

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: The input string is not correct.

What you need to do in order to get rid of the error and get the result line:

 {Name:Value} 
  • 3
    Still not a duplicate, though similar. Interpolation and composite formatting are different things. - Pavel Mayorov

1 answer 1

Opening and closing parentheses is interpreted as the starting and ending element for the string formatting function. In order to display a curly bracket in a string, you need to duplicate it {{ to open a bracket and }} to close it. The corrected version will look as follows:

 string.Format("{{Name:{0}}}", "Value"); 

Details can be viewed on MSDN , as well as here.