我正在尝试使用 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/