inline if code example

Example 1: js inline if

var a = 2;
var b = 3;    
var c = ((a < b) ? 'minor' : 'major');

Example 2: ternary operator

(condition) ? (if true, do this) : (otherwise, do this)

Example 3: c# ternary

// ---------------- Syntax of Ternary Operators ----------------- //

string stateOfMatter;
int temperature = 23;


// ---- For just one condition ---- //
stateOfMatter = temperature < 0 ? "Solid": "Liquid";
  
// If temperature is below zero, then stateOfMatter is solid, otherwise
// it will be liquid
  
  
// ---- For more conditions ---- //
stateOfMatter = temperature < 0 ? "Solid" : (temperature > 100 ? "Gas" : "Liquid");

Example 4: c# inline if

(condition ? [true value] : [false value])

int x = a ? b : c;

Example 5: c# ternary condition

condition ? consequent : alternative

Example 6: inline if in html component

Condition ? Block_For_True : Block_For_False