web analytics

Escape curly brace in string.Format()

Options

codeling 1599 - 6654
@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 :-{

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com