?? is a binary operator. If the left operand is not empty, it returns the left operand, otherwise it returns the right operand. Therefore, in some specific occasions, it can be used instead of the ?: operator to simplify code writing.
Example 1:
Copy the codeThe code is as follows:
int length = ["l"] != null ? (["l"]) : 0;
Use the ?? operator:
Copy the codeThe code is as follows:
int length = (["l"] ?? "0");
Example 2:
Copy the codeThe code is as follows:
int? m = null;
int n = m == null ? (int)m : 0;
Use the ?? operator:
Copy the codeThe code is as follows:
int? m = null;
int n = m ?? 0;
References:
[1].?? operator (C# reference):/zh-cn/library/ms173224(v=vs.80).aspx