Comparing nullable DateTime?

前端 未结 5 1000
星月不相逢
星月不相逢 2020-12-10 10:03

Looking for a better way to compare a nullable date time than the following:

Any suggestions?

// myobject.ExpireDatetime is of DateTime?
//
if (!myob         


        
5条回答
  •  独厮守ぢ
    2020-12-10 10:50

    If ExpireDateTime is a Nullablei would do following instead:

    if (ExpireDateTime.HasValue && ExpireDateTime < DateTime.Now.ToUniversalTime())
    { 
    }
    

提交回复
热议问题