Monday, August 15, 2016

Escape curly brace in String.Format()

To escape curly braces in String.Format(), you have to prepend "{" symbol in the opening brace and append "}" in the closing brace as shown below.
Code:
string firstName = "Michael";
string lastName = "Jordan";
string output = String.Format("Your name is: {{ {0}, {1} }}", firstName, lastName);
Console.WriteLine(output);

Output:

0 comments:

Post a Comment