[英]Filter List based on another list
i have two lists based on other objects. 我有两个基于其他对象的列表。
List<Emyployee> emyployeeList;
List<Display> displayEmployeeList;
both of them have the id's of the employees, but the second list only have a few of them. 他们两个都有雇员的ID,但是第二个列表中只有几个。 I want to filter the employeeList that i have all id's that arent in the displayEmployeeList.
我想过滤我在displayEmployeeList中拥有所有id的employeeList。
how can i do that? 我怎样才能做到这一点?
If displayEmployeeList
has many items you can find useful to create a kind of index (like that of RDBMS): 如果
displayEmployeeList
有很多项目,您会发现创建一种索引 (如RDBMS的索引)很有用:
// let id be integer
HashSet<int> ids = new HashSet<int>(displayEmployeeList
.Select(item => item.id)
);
// Just Linq where
var result = emyployeeList
.Where(item => !ids.Contains(item.id));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.