当前位置: 代码迷 >> C# >> 空归拢操作符?(C#)
  详细解决方案

空归拢操作符?(C#)

热度:368   发布时间:2016-04-28 08:19:15.0
空合并操作符??(C#)

??二元操作符在对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;

 

  相关解决方案