CSharp - Operator Ternary operator

Introduction

Ternary operator has the form q ? a : b

if condition q is true, a is evaluated, else b is evaluated.

For example the following code use ternary to get the bigger value of two.

int Max (int a, int b)
{
       return (a > b) ? a : b;
}

We can use the if statement to code the same logic.

if(a > b){
  return a;
}else{
  return b;
}

Exercise