System.DateTime? vs System.DateTime

后端 未结 6 1079
心在旅途
心在旅途 2021-02-05 02:53

I was writing to some code where I needed to read the date value from a Calendar control in my page (Ajax toolkit: calendar extender).

The code below:

6条回答
  •  情深已故
    2021-02-05 03:25

    var Endtime = DateTime.Now();
    DateTime startTime = item.REPORT_TIME.HasValue ? item.REPORT_TIME.Value : Endtime;
    

    Means: the type of item.item.REPORT_TIME is system.DateTime?
    howerver the type of startTime is system.DateTime; so the code can changed it like

    `var Endtime=DateTime.Now; var startTime=item.REPORT_TIME.HasValue?Convert.ToDateTime(item.REPORT_TIME.HasValue):Endtime

    `

提交回复
热议问题