The ternary operator : Ternary Operator : Operator C# Examples


C# Examples » Operator » Ternary Operator »

 

The ternary operator









    
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);

    }

}
    
   
  
   



Output

result = 20
result = 10


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Ternary Operator