c# - LINQ 查询查询具有数组成员的列表

标签 c# .net linq linq-to-objects

我正在尝试使用 LINQ 查询列表。

查询语句包含应与数组中的项目匹配的条目。

换句话说,从 SourceList 中获取与 items 数组中的任何一项匹配的条目。 示例:

private List<string> GetSearchResult(List<string> SourceList,
    string name, string[] items)
{
     IEnumerable<string> QueryList = SourceList.Where
         (entry => enrty.name == name && entry.id == <any item from items>)
}

我想构建一个循环遍历 items 数组的查询字符串。 我想知道是否有一种有效的方法可以做到这一点。

最佳答案

private List<string> GetSearchResult(List<string> SourceList,
    string name, string[] items)
{
     return SourceList.Where(entry => entry.name == name 
         && items.Contains(entry.id))
}

关于c# - LINQ 查询查询具有数组成员的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4260897/

相关文章:

c# - 两个同名字段

c# - 词典性能

c# - 如何获取 N 个热 Observable<decimal> 实例的 "last"项的总和?

c# - LINQ 按问题分组

c# - EWS : Exchange Web Service. 多次调用 ResolveName - 性能命中(当然)

c# - 对线程池输出进行排序以流式传输数据

.net - Windows 10 通用应用程序中的证书固定

c# - LINQ to Entities 搜索多列,按匹配列的总权重排序

c# - 如何从一组整数组中找到最小的不同组?

linq - 在 EF 中定义逗号分隔字符串并与 Linq 一起使用