linq返回列表包含找到的项目

时间:2016-03-02 00:24:58

标签: c# linq-to-sql

使用linq:我有一个服务对象列表

services[0]
id=1, name="rental", ...

services[1]
id=2. name="buy", ...

services[2]
id=3. name="both", ...

...等

我有array []包含从所选列表中检索的服务[] = 1,3

 foreach(var service in services.where(x=>x.id.Contains(selected))

这就是我被困在哪里如何将contains添加到where子句?

构建错误:包含找不到的运算符

1 个答案:

答案 0 :(得分:0)

尝试在数组上使用Contains而不是id

foreach(var service in services.where(x => selected.Contains(x.id))