c# - 按属性对对象列表进行排序 C#

标签 c# list sorting

我有这门课:

public class Leg
{
    public int Day { get; set; }
    public int Hour { get; set; }
    public int Min { get; set; }
}

我有一个获取腿列表的函数,称为 GetLegs()

List<Leg> legs = GetLegs();

现在我想对这个列表进行排序。所以我必须首先考虑日期,然后是小时,最后是分钟。 这个排序应该怎么解决?

谢谢

最佳答案

也许是这样的:

List<Leg> legs = GetLegs()
                .OrderBy(o=>o.Day)
                .ThenBy(o=>o.Hour)
                .ThenBy(o=>o.Min).ToList();

关于c# - 按属性对对象列表进行排序 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9716273/

相关文章:

c++ - C++中的链表相乘

magento - 关于 magento 1.7.0.2 中观看次数最多的排序

c# - 如何为 N 单元测试使用多个 TestCaseSource 属性

c# - 为什么我在使用 FileStream.Write 时会越界?

python - C 数组和 Python 列表之间的区别

c# - Entity Framework 核心 ForEachAsync

c# - 静态变量和多线程

c# - 如何在 Visual Studio 2017 中更新对 VSConstants 的引用

java - 如何在 Java 中对泛型类型列表进行排序

C 整数数组排序