Find max count of a list of custom types

后端 未结 4 2056
耶瑟儿~
耶瑟儿~ 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条回答
  •  终归单人心
    2021-01-24 12:14

    1) It depends on where the data is coming from. A database, file from disk, in memory collection. Often the List or whatever structure is determined by the source.

    2) Your LINQ is getting the max number, not the Manager with the highest count. Try:

    public static Manager GetBestManager(List managerList)
    {
        Manager m = managerList.OrderByDescending(x => x.EmployeesManaged.Count).First();
        return m;
    }
    

提交回复
热议问题