Search code examples
c#javacternary-operator

How does the ternary operator work?


Please demonstrate how the ternary operator works with a regular if/else block. Example:

Boolean isValueBig = value > 100 ? true : false;

Exact Duplicate: How do I use the ternary operator?


Solution

  • Boolean isValueBig = ( value > 100  ) ? true : false;
    
    // above line is same as:
    
    Boolean isValueBig;
    
    if(  value > 100 ) { 
          isValueBig = true;
    } else { 
         isValueBig = false;
    }