condition ? expression1 : expression2;
When condition is true, expression1 is executed. Experssion2 is executed when false.
It is used only in assignment statement.
Expression1 and experssion2 must have implicit conversions from one to another.
It can also be used to return a reference to the result of the condition . (C# 7.2)
static void ConditionalRefExample()
{
var array1=new int[] { 1, 2, 3 };
var array2=new int[] { 10, 20, 30 };
int i = 5;
ref int ref1 = ref ((i < 3) ? ref array1[i] :ref array2[i-3]);
ref1 = 0;
int j = 2;
((j<3)?ref array1[j]: ref array2[j-3]) = 100;
Console.WriteLine(string.Join(" ", array1));
Console.WriteLine(string.Join(" ", array2));
// result:
// 1, 2, 100
// 10, 20, 0
}