Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Descending SortedList
Message
From
25/04/2009 12:46:40
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Descending SortedList
Miscellaneous
Thread ID:
01396377
Message ID:
01396377
Views:
105
I have the following SortedList:
SortedList<DateTime, Bookmark> BookMarks = new SortedList<DateTime, Bookmark>();
Where BookMark is a custom object of my creation. I would like to have this list automatically sort in decending order, i.e., the most recent DateTime first, etc.

I have created the following custom Compare Class:
    public class DecendingDateCompare : IComparer
    {
        public int Compare(object x, object y)
        {
            //   I am passing objects x, y to conform to the IComparer signature??
            try
            {
                DateTime d1 = DateTime.Parse(x.ToString());
                DateTime d2 = DateTime.Parse(y.ToString());
                return d1.CompareTo(d2)*-1;
            }
            catch (System.Exception ex)
            {
                return x.ToString().CompareTo(y.ToString());
            }
        }
    }
If I leave the above declaration of my SortedList as above, no errors, but as soon as I try the below I get errors:
 SortedList<DateTime, Bookmark> BookMarks = new SortedList<DateTime, Bookmark>(new DecendingDateCompare());
The errors are:
The best overloaded method match for 'System.Collections.Generic.SortedList<System.DateTime,Marketware.Bookmark>.SortedList(int)' has some invalid arguments
Argument '1': cannot convert from 'Marketware.DecendingDateCompare' to 'int'


Any Ideas of where I am going wrong? Thanks!!


Bob
Next
Reply
Map
View

Click here to load this message in the networking platform