Mit*_*eat 16
??是可空类型的null-coalescing运算符.
object obj = canBeNull ?? alternative;
// equivalent to:
object obj = canBeNull != null ? canBeNull : alternative;
Run Code Online (Sandbox Code Playgroud)
http://msdn.microsoft.com/en-us/library/ms173224.aspx请参阅此说明.这是一个运营商
的??操作者定义了当一个空类型被分配到非空类型要返回的默认值.
// ?? operator example.
int x = null;
// y = x, unless x is null, in which case y = -1.
int y = x ?? -1;
// Assign i to return value of method, unless
// return value is null, in which case assign
// default value of int to i.
int i = GetNullableInt() ?? default(int);
string s = GetStringValue();
// ?? also works with reference types.
// Display contents of s, unless s is null,
// in which case display "Unspecified".
Console.WriteLine(s ?? "Unspecified");
Run Code Online (Sandbox Code Playgroud)