我有一个IEnumerable<Objects.LabourHours>类型的数据收集,其中包含各种雇员的劳动记录.我希望过滤列表并仅返回选定雇员的记录,该记录由包含EmployeeID的int[] employees列表指定.
I have a data collection of type IEnumerable<Objects.LabourHours> containing labour records for various employees. I wish to filter the list and return only records for selected employees, which is specified by a list of int[] employees containing the EmployeeIDs.
class LabourHours { public int ID {get;set;} public int EmployeeID {get;set;} public int HoursWorked {get;set;} }我将如何处理?我确信这已经被问过了,但是我在这里找不到任何类似的东西.我发现最接近的是按用户ID对记录进行分组,这不是我所需要的-我需要实际的记录.
How would I go about this? I am sure this has been asked before but I can't find anything similar on here. The closest I have found involves grouping the records by UserID, which is not what I need - I need the actual records.
推荐答案您可以使用Contains方法通过LINQ Where过滤列表:
You can filter your list with LINQ Where using Contains method:
var result = list.Where(x => employees.Contains(x.EmployeeID));更多推荐
Linq选择所有项目匹配数组
发布评论