運算子 ??及?:的運用
??
int? x = null;
int y = x ?? 1;
Console.WriteLine(y);
輸出結果為:1
?:
int x = 0;
Console.WriteLine(x > 5 ? 1 : -1);
Console.WriteLine(x == 0 ? 1 : -1);
Console.WriteLine(x < 5 ? 1 : -1);
輸出結果為:-1,1,1
參考: https://msdn.microsoft.com/zh-tw/library/zakwfxx4(v=vs.100).aspx