使用LINQ对列表进行排序 [英] Sort a list using LINQ
本文介绍了使用LINQ对列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象列表,想按2nd和3rd属性值对其进行排序,但是该列表从未按我的预期进行排序.谁能帮我.以下是代码:
list = list.OrderBy(a => a.IsSelected).OrderBy(s => s.Score).ToList();
(如果选择了该属性,则放在顶部)
这是我的对象:
I have a list of objects and would like to sort it by the 2nd and 3rd property values but the list never sorts as I expected. Could anyone help me please. Here's the code:
list = list.OrderBy(a=>a.IsSelected).OrderBy(s=>s.Score).ToList();
(if the property is selected, put on top)
And here's my object:
public class Name
{
int ID { get; set; }
bool IsSelected { get; set; }
int Score { get; set; }
}
List<Name> list = new List<Name>();
推荐答案
我相信您需要对第二个OrderBy使用ThenBy.
希望这会有所帮助.
I believe you need to use ThenBy for the second OrderBy.
Hope this helps.
这篇关于使用LINQ对列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文