Linq选择所有项目匹配数组

编程入门 行业动态 更新时间:2024-10-07 00:22:41
本文介绍了Linq选择所有项目匹配数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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选择所有项目匹配数组

本文发布于:2023-10-19 01:44:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506026.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   项目   Linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!