-1
var condition = false;
Foo($"String is {(condition ? "True" : "False")} works");

but

Foo($"String is {(condition ? "True" 
                            : "False")} fails");

I got compile error when I nicely format the conditional operator within my string interpolated statement?

  • use verbatim strings.... Foo($@"String is {(condition ? "True" : "False")}fails"); – Ansil F Aug 01 '17 at 09:15
  • Thanks for the reply but I read about the 'solution' by using $@ instead which is weird because the conditional-operator is already needs to be separated by parenthesis and therefor its contents should not be interpreted as format specifiers anymore; using $@ makes also impossible to use format literals like \t ... – Leo Rozing Aug 01 '17 at 09:27

1 Answers1

0

Use @

Foo($@"String is {(condition ? "True" 
                            : "False")} fails");
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116