27

I have the following list:

IEnumerable<Car> cars;

The Car object has a model and a year. I want to sort this list by model and then year (within model).

What is the best way of doing this?

Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
leora
  • 188,729
  • 360
  • 878
  • 1,366

1 Answers1

66
var sortedCars = cars.OrderBy(c => c.Model).ThenBy(c => c.Year);
Anthony Pegram
  • 123,721
  • 27
  • 225
  • 246