C# Program – How to Escape Braces ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

This post shows you a quick way on how you can escape braces or curly brackets in C# when using string format.

How to escape braces(curly brackets) in C#?

When using string.format in C#, you might have a requirement where you would need to escape braces. One of the easiest ways to escape braces in C# is to use { thrice for the opening brace and use } thrice for the closing brace.

Here’s a sample code snippet in C# demonstrating how you can do it.

using System;
namespace AbundantcodeSample
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "Abundantcode, top, programming website";
            
            // string interpolation 
            string output = $" {{{input}}}";

            Console.WriteLine(output);
        }
        
    }
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: