c# conditional operator code example
Example 1: conditional if statement c# programming
is this condition true ? yes : no
Example 2: c# ternary
string stateOfMatter;
int temperature = 23;
stateOfMatter = temperature < 0 ? "Solid": "Liquid";
stateOfMatter = temperature < 0 ? "Solid" : (temperature > 100 ? "Gas" : "Liquid");
Example 3: c# if statement one line
someValue = condition ? newValue : someValue;
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: c# ternary operator
double sinc(double x) => x != 0.0 ? Math.Sin(x) / x : 1;
Console.WriteLine(sinc(0.1));
Console.WriteLine(sinc(0.0));