Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Descending SortedList
Message
From
26/04/2009 16:34:24
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01396377
Message ID:
01396433
Views:
45
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
Next
Reply
Map
View

Click here to load this message in the networking platform