[英]linq return list where Contains items found
using linq: I have an object list of services 使用linq:我有服务的对象列表
services[0]
id=1, name="rental", ...
services[1]
id=2. name="buy", ...
services[2]
id=3. name="both", ...
..etc ..等等
I have array[] contains what services to retrieve from the list selected[]=1,3 我有array []包含要从所选列表中检索哪些服务[] = 1,3
foreach(var service in services.where(x=>x.id.Contains(selected))
this is where I am stuck how do I add contains into where clause? 这就是我卡住的地方,如何将包含添加到where子句中?
build error: contains operator not found 生成错误:找不到包含运算符
尝试在您的数组上使用Contains
而不是id
。
foreach(var service in services.where(x => selected.Contains(x.id))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.