Using LINQ to Objects to find items in one collection that do not match another

后端 未结 8 1888
清酒与你
清酒与你 2020-12-29 05:04

I want to find all items in one collection that do not match another collection. The collections are not of the same type, though; I want to write a lambda expression to spe

8条回答
  •  一个人的身影
    2020-12-29 05:53

    Managers are employees, too! So the Manager class should subclass from the Employee class (or, if you don't like that, then they should both subclass from a parent class, or make a NonManager class).

    Then your problem is as simple as implementing the IEquatable interface on your Employee superclass (for GetHashCode simply return the EmployeeID) and then using this code:

    var nonManagerEmployees = employeeList.Except(managerList);
    

提交回复
热议问题