Comparing nullable DateTime?

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

    I would recommend you to use the following:

    int y = Nullable.Compare(DateTime.UtcNow, x); 
    
    // x is the nullable date time object.
    // y will be '-1' if x is greater than DateTime.UtcNow
    

提交回复
热议问题