First of all, unless you are stuck with using framework 1.1, you should not be using an ArrayList
at all. You should use a strongly typed generic List<DateTime>
instead.
For custom sorting there is an overload of the Sort
method that takes a comparer. By reversing the regular comparison you get a sort in descending order:
list.Sort(delegate(DateTime x, DateTime y){ return y.CompareTo(x); });
Update:
With lambda expressions in C# 3, the delegate is easier to create:
list.Sort((x, y) => y.CompareTo(x));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…