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.

1
  • 1
    What compilation error? Commented Dec 9, 2018 at 10:16

3 Answers 3

4

The colon ends the interpolation. Just parenthesize the condition :

string Test(bool @bool) => $"you're {(@bool ? "hired":"fired")} Have a nice day!";
Sign up to request clarification or add additional context in comments.

Comments

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!";

Comments

1

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

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

$ - string interpolation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.