Use ternary operator in Console.WriteLine function : Ternary Operator « Operator « C# / CSharp Tutorial






using System;

class MainClass
{
   static void Main()
   {
      int x = 10, y = 9;
      Console.WriteLine("x is{0} greater than y",
                            x > y          // Condition
                            ? ""           // Expression 1
                            : " not");     // Expression 2

      y = 11;
      Console.WriteLine("x is{0} greater than y",
                            x > y          // Condition
                            ? ""           // Expression 1
                            : " not");     // Expression 2
   }
}
x is greater than y
x is not greater than y








3.8.Ternary Operator
3.8.1.The ? Operator
3.8.2.The ternary operator
3.8.3.Use ternary operator in Console.WriteLine function
3.8.4.Prevent a division by zero using the ? operator
3.8.5.Simplest Data type cast operator