Link to home
Start Free TrialLog in
Avatar of Zeus2009
Zeus2009

asked on

vb.net sort arraylist of dates

Hi All,

I am looking for a simple example of sorting an arraylist of dates in descending order.

i am using VS2005, vb.net, .Net 2

Thanks
Zeus
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another possibility:
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); });

Source: http://stackoverflow.com/questions/844251?sort=newest