Comparing nullable DateTime?

前端 未结 5 1015
星月不相逢
星月不相逢 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:59

    Use the Value property of the nullable:

    objet.ExpireDateTime.Value
    

    if (!object.ExpireDateTime.IsNull() 
        && DateTime.Compare(objet.ExpireDateTime.Value, 
                            DateTime.Now.ToUniversalTime()) < 0)
    { 
    }    
    

提交回复
热议问题