来自列表的C#不同列表

这个问题在这里已经有了答案:

  • LINQ对特定属性的Distinct()17的答案

  • 您可以使用GroupBy作为关键字的匿名类型:

    occupancyResultList = occupancyResultList
            .GroupBy(x => new { x.on_date, x.type_code, x.available })
            .Select(g => g.First())
            .ToList();
    

    DistinctBy方法:

    occupancyResultList = occupancyResultList
            .DistinctBy(x => new { x.on_date, x.type_code, x.available })
            .ToList();
    
    链接地址: http://www.djcxy.com/p/51295.html

    上一篇: C# Distinct List from a List

    下一篇: Linq to get distinct property