??二元操作符在對first??second求值時,大致會經歷以下步驟:
1)對first進行求值;
2)如果結果非空,則該結果就是整個表達式的結果;
3)否則求second的值,其結果作為整個表達式的結果。
例如:
1 DateTime birth;
2 DateTime? death;
3
4 public TimeSpan Age{
5 get{
6 return (death??DateTime.Now)-birth;
7 }
8 }
1 Address contact = user.ContactAddress?? 2 order.ShippingAddress?? 3 user.BillingAddress;