Use ternary operator in Console.WriteLine function : Ternary Operator : Operator C# Examples


C# Examples » Operator » Ternary 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
      }
}
    
   
  
   



Output

x is greater than y
x is not greater than y


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Ternary Operator