public class CarSpecs
{
public String CarName { get; set; }
public String CarMaker { get; set; }
public DateTime CreationDate { get; set; }
}
I would just use the build in List.Sort method. It uses the QuickSort algorithm which on average runs in O(n log n).
This code should work for you, I change your properties to auto-properties, and defined a static CompareCarSpecs method that just uses the already existing DateTime.CompareTo method.
class Program
{
static void Main(string[] args)
{
List cars = new List();
cars.Sort(CarSpecs.CompareCarSpecs);
}
}
public class CarSpecs
{
public string CarName { get; set; }
public string CarMaker { get; set; }
public DateTime CreationDate { get; set; }
public static int CompareCarSpecs(CarSpecs x, CarSpecs y)
{
return x.CreationDate.CompareTo(y.CreationDate);
}
}
Hope this helps.