Mega Code Archive

 
Categories / C# Tutorial / Operator
 

Use ternary operator in Console WriteLine function

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