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); } } }
Leave a Reply