What I needed to do was to sort a list of dates and corresponding names in order of date. Problem was that sometimes the dates duplicate and as a result, a standard SortedList would crash (since keys need to be unique). Anyway, here's a workaround to that problem. We create a new class for the project as follows:
public class ComparableDateTime : IComparable
{
private DateTime mDT;
public int CompareTo(object obj)
{
if (mDT.Ticks < ((ComparableDateTime)obj).mDT.Ticks) return -1;
return 1;
}
public ComparableDateTime(DateTime myDate)
{
mDT = myDate;
}
}
Then once we have the class, we can declare a SortedList with that class:
using System.Collections.Generic;
SortedList<ComparableDateTime, string> mySortedList = new SortedList<ComparableDateTime,string>();
DateTime someDate = DateTime.Today;
mySortedList.Add(new ComparableDateTime(someDate,"someString");
mySortedList.Add(new ComparableDateTime(someDate,"someString2");
for (int i = 0; i < mySortedList.Count; i++)
{
writer.Write(mySortedList.Values[i].ToString());
}