Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The ?? operator is used to return the left operand if it's not null, otherwise, it returns the right operand. It's equivalent to (left != null ? left : right).
string a = null;
object b = a ?? new object();
object c = b ?? "b is null!";
int? x = null;
int y;
// These statements should be equivalent:
y = x ?? default(int);
y = x.GetValueOrDefault();
y = x.HasValue ? x.Value : default(int);
y = x != null ? x.Value : default(int);
For more info, please read: ?? Operator (C# Reference) and default Keyword in Generic Code (C# Programming Guide)