Looking for a contract position
in Toronto area as a Senior .NET Developer
Toronto, ON, M6P 2P2
Tel: 647.328.3809
Email: 

How to use curly brackets inside of String.Format

String.Format provides inserting variables inside of the string, indicated with curly brackets and index, for example

String s = string.Format"Hello {0}", name)

But if you need to use curly brackets inside of string format you will get exception, because compiler does not know if you trying to insert curly bracket or replacing string. So you can get exception

String s = string.Format("{name} = {0}", name); // exception

But there is a simple solution to avoid exception, you need to use double curly brackets.

String s = string.Format("{{name}} = {0}", name); // ok
 
Powered by AtomicCms content management system