-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?

Shury
  • 468
  • 3
  • 15
  • 49

1 Answers1

2
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.

gilliduck
  • 2,762
  • 2
  • 16
  • 32