-1

I have a boolean isEuropean and based on it's value I want to write

Console.WriteLine("This individual is/is not European");

Is it possible in C# to add a conditional directly inside a string with no additional variables created?

0

1 Answer 1

3
bool isEuropean = true;
Console.WriteLine($"This individual {(isEuropean ? "is" : "is not")} European");

Yes, you can do string interpolation with a ternary, make sure you contain the ternary in parentheses.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.