How to escape curly braces in String.Format with C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "8 - 0 - 2 - 6";
        
        string code = String.Format("Code = {{{0}}}", s);      
        Console.WriteLine(code);
        
        string result = String.Format("Result = {{C# - 18}}");
        Console.WriteLine(result);
    }
}




/*
run:

Code = {8 - 0 - 2 - 6}
Result = {C# - 18}

*/

 



answered Jun 6, 2021 by avibootz
edited Jun 6, 2021 by avibootz

Related questions

1 answer 150 views
150 views asked Jun 6, 2021 by avibootz
1 answer 166 views
166 views asked Feb 7, 2017 by avibootz
1 answer 179 views
1 answer 192 views
1 answer 426 views
...