How to convert DateTime? to DateTime

前端 未结 11 2006
醉话见心
醉话见心 2020-12-07 15:17

I want to convert a nullable DateTime (DateTime?) to a DateTime, but I am getting an error:

Cannot implicitly convert type

11条回答
  •  伪装坚强ぢ
    2020-12-07 15:56

    MS already made a method for this, so you dont have to use the null coalescing operator. No difference in functionality, but it is easier for non-experts to get what is happening at a glance.

    DateTime updatedTime = _objHotelPackageOrder.UpdatedDate.GetValueOrDefault(DateTime.Now);
    

提交回复
热议问题