I have a list of DateTime and null values that I want to sort. It looks something like this.
List<DateTime?> allDateTimes = new List<DateTime?>();
allDateTimes.Add(new DateTime(2015, 12, 31, 5, 10, 20));
allDateTimes.Add(Null);
allDateTimes.Add(new DateTime(2014, 11, 15, 5, 10, 20));
allDateTimes.Add(new DateTime(2014, 11, 18, 5, 10, 20));
How would I do to sort this by earliest date and null at last place. I have tried something like this
allDateTimes.Sort((a, b) => a.CompareTo(b));
and
allDateTimes.Sort((a, b) => a.HasValue.CompareTo(b));
But I cant Sort this way because of the null values.