Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Descending SortedList
Message
From
02/05/2009 04:09:05
 
 
To
30/04/2009 13:33:58
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01396377
Message ID:
01397592
Views:
38
Glad it helped...

>Thank you. That was the ticket...i.e., generic comparer. I just plugged it in to the previous code and we're in business!!
>
>bob
>
>>Hi,
>>As mentioned I didn't give *any* thought to the logic in the return line. My guess is that, as it stands, it would give ascending rather than descending order and so will need to be adjusted...
>>Best,
>>Viv
>>>Thanks!! That gets me through the compile. I'll let you know if it works to sort the list the way I need it to...
>>>
>>>bob
>>>
>>>
>>>>Hi,
>>>>
>>>>I think you need the generic comparer Something like:
>>>>   public class DecendingDateCompare : System.Collections.Generic.IComparer<DateTime>
>>>>    {
>>>>         public int Compare(DateTime x, DateTime y)
>>>>        {
>>>>            return x.CompareTo(y);
>>>>        }
>>>>     }
Return logic might be wrong but you get the idea. HTH
>>>>Viv
>>>>
>>>>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform