The new String Interpolation and Ternary Operator

A quick tip for the new C# string interpolation. The new string interpolation has made things more simpler and readable. One might be tempted to include ternary operators within string interpolation.

However if you attempt something like following, the compiler would throw an error

Console.WriteLine($"{1==1?"Msg1":"Msg2"}");

The fix is as simple as it can get. Just include a brace within your ternary statement.

Console.WriteLine($"{(1==1?"Msg1":"Msg2")}");

That’s it. Brace up for a week with lot of fun and coding.