The ternary operator : Ternary Operator « Operator « C# / CSharp Tutorial






class MainClass
{

  public static void Main()
  {

    int result;

    result = 10 > 1 ? 20 : 10;
    System.Console.WriteLine("result = " + result);

    result = 10 < 1 ? 20 : 10;
    System.Console.WriteLine("result = " + result);

  }

}
result = 20
result = 10








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