8
Q:

c# inline if


// ---------------- 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");
  
1
(condition ? [true value] : [false value])

int x = a ? b : c;
1
is this condition true ? yes : no
4
condition ? consequent : alternative
1

New to Communities?

Join the community