1

string Test(bool @bool) => $"you're {@bool?"hired":"fired"} Have a nice day!";

The code above results in compilation error. But why? Notice that string test = $"this {"is"} working"; works.

Amad
  • 25
  • 9

3 Answers3

4

The colon ends the interpolation. Just parenthesize the condition :

string Test(bool @bool) => $"you're {(@bool ? "hired":"fired")} Have a nice day!";
Arthur Attout
  • 2,701
  • 2
  • 26
  • 49
1

For this issue you you can not use of ?,: of some thing like these, for using of these you have to set Exactly your condition should put in () like:

string Test(bool @bool) => $"you're {(@bool ? "hired":"fired")} Have a nice day!";
AmirReza-Farahlagha
  • 1,204
  • 14
  • 26
1

You can try to use () contain your ?: Operator

string Test(bool @bool) => $"you're {(@bool ? "hired":"fired")} Have a nice day!";

$ - string interpolation

D-Shih
  • 44,943
  • 6
  • 31
  • 51