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

后端 未结 8 1894
清酒与你
清酒与你 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:54

    This is almost the same as some other examples but less code:

    employees.Except(employees.Join(managers, e => e.Id, m => m.EmployeeId, (e, m) => e));
    

    It's not any simpler than employees.Where(e => !managers.Any(m => m.EmployeeId == e.Id)) or your original syntax, however.

提交回复
热议问题