The ?? Operator

From Logic Wiki
Jump to: navigation, search


The briefest explanation is this: ?? is used a lot like the conditional operator (?:), except instead of any condition, it will only check if the value on the left is null. If it is not null, it returns the item on the left - otherwise it will return the thing on the right.

string myString = null;
string myOtherString = myString ?? "Something Else";
Console.WriteLine(myOtherString);
//Output: "Something Else"