How to convert DateTime? to DateTime

前端 未结 11 2037
醉话见心
醉话见心 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:45

    Consider using the following which its far better than the accepted answer

    DateTime UpdatedTime = _objHotelPackageOrder.UpdatedDate == null 
        ? DateTime.Now : (DateTime)_objHotelPackageOrder.UpdatedDate;
    

提交回复
热议问题