开发者

How to Sort IEnumerable List?

开发者 https://www.devze.com 2023-01-04 07:21 出处:网络
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).

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?


var sortedCars = cars.OrderBy(c => c.Model).ThenBy(c => c.Year);
0

精彩评论

暂无评论...
验证码 换一张
取 消