Find max count of a list of custom types

后端 未结 4 2059
耶瑟儿~
耶瑟儿~ 2021-01-24 12:03

I have a mock application where an inheritance chain like Employee,Manager,President etc.

The Employee class looks like

class Employee
    {         


        
4条回答
  •  旧时难觅i
    2021-01-24 12:20

    see my answer on this post: How can I get LINQ to return the object which has the max value for a given property?

    You can use the Aggregate function in System.Linq

    Aggregate is faster because it simply runs through the collection once and takes the biggest as it goes. OrderBy essentially has to do a bubble sort which is more costly.

提交回复
热议问题