Suppose you need to sort an array of dates in descending order...
DateTime[] availableDates = allMailDates.ToArray();
Array.Sort(availableDates, delegate(DateTime d1, DateTime d2) {
return Math.Sign(d2.ToBinary() - d1.ToBinary());
});
DateTime[] availableDates = allMailDates.ToArray();
Array.Sort(availableDates, delegate(DateTime d1, DateTime d2) {
return Math.Sign(d2.ToBinary() - d1.ToBinary());
});
2 comments:
I don't see any guarantee on the ordering of DateTime.ToBinary in the docs(). I don't see any guarantee on the range used (apart from 64bits, which is not enough to prevent overflow).
ะก# 3.0 way:
Array.Sort(availableDates, (x1,x2)=>Math.Sign(x2.ToBinary() - x1.ToBinary()));
;)
Post a Comment