Using curly braces in a format string in C#

Because curly braces are used in C# to indicate where values should be pasted in, like this…

sb.AppendFormat(“Email: {0}”, sEmail);

…therefore, if you need to display curly braces in the final string, you’ll need to escape them, like this:

sb.AppendFormat(“var oContact = {email:'{0}’}“, sEmail);

Print Friendly, PDF & Email