G
Guest
What is the recommended way for comparing two nullabe DateTime types using
the CompareTo method.
DateTime? d1
DateTime? d2
return d1.Value.CompareTo(d2.Value) //This obvoiusly will fail if one is null
return d1.GetDefaultOrValue().CompareTo(d2.GetDefaultOrValue()) //this works
but it is a hack as you are converting a null type to DateTime.MinValue and
then doing a compare.
I wish to return
-1 if d1 < d2,
0 if d1 = d2,
1 if d1 > d2
Thanks
the CompareTo method.
DateTime? d1
DateTime? d2
return d1.Value.CompareTo(d2.Value) //This obvoiusly will fail if one is null
return d1.GetDefaultOrValue().CompareTo(d2.GetDefaultOrValue()) //this works
but it is a hack as you are converting a null type to DateTime.MinValue and
then doing a compare.
I wish to return
-1 if d1 < d2,
0 if d1 = d2,
1 if d1 > d2
Thanks