The List<T>
class makes this trivial for you, since it contains a Sort
method. (It uses the QuickSort algorithm, not Bubble Sort, which is typically better anyway.) Even better, it has an overload that takes a Comparison<T>
argument, which means you can pass a lambda expression and make things very simple indeed.
Try this:
CarList.Sort((x, y) => DateTime.Compare(x.CreationDate, y.CreationDate));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…