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.
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 argumentsArgument '1': cannot convert from 'Marketware.DecendingDateCompare' to 'int'