按属性对对象列表进行排序C# [英] Sort list of object by properties c#
本文介绍了按属性对对象列表进行排序C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我上了这个课:
public class Leg
{
public int Day { get; set; }
public int Hour { get; set; }
public int Min { get; set; }
}
我有一个获取腿部列表的函数,称为GetLegs()
I have a function that gets a list of legs, called GetLegs()
List<Leg> legs = GetLegs();
现在,我想对该列表进行排序.因此,我首先必须考虑日期,然后是小时,最后是分钟. 我应该如何解决这种排序?
Now I would like to sort this list. So I first have to consider the day, then the hour, and at last the minute. How should I solve this sorting?
谢谢
推荐答案
也许是这样的:
List<Leg> legs = GetLegs()
.OrderBy(o=>o.Day)
.ThenBy(o=>o.Hour)
.ThenBy(o=>o.Min).ToList();
这篇关于按属性对对象列表进行排序C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文