web analytics

Escape curly brace in string.Format()


codeling 1595 - 6639
@2024-02-15 22:51:02

How do I display a literal curly brace character when using the String.Format method? The answer is that you need to escape curly brace by using double braces ({{ and }}). 


@2024-02-15 22:55:09
Console.WriteLine($"He asked, \"Is your name {name}?\", but didn't wait for a reply :-{{");

// Output is:

// He asked, "Is your name Horace?", but didn't wait for a reply :-{


You must Sign In to comment on this topic.

© 2024 Digcode.com