C# interpolated string with conditional-operator
You need to put the string in parentheses within {}
, so: {(1 == 1 ? "yes" : "no")}
.
$"test {(foo ? "foo is true" : "foo is false")}";
The code inside the parentheses returns a variable, and that's the only thing allowed inside the curly brackets. The colon ':' is a special character in string interpolation, hence it needs to be parenthesised.