C# linq返回列表,其中包含找到的项
使用linq:我有一个服务的对象列表C# linq返回列表,其中包含找到的项,c#,linq-to-sql,C#,Linq To Sql,使用linq:我有一个服务的对象列表 services[0] id=1, name="rental", ... services[1] id=2. name="buy", ... services[2] id=3. name="both", ... 等等 我已确定数组[]包含要从所选列表中检索的服务[]=1,3 foreach(var service in services.where(x=>x.id.Contains(selected)) 这就是我被卡住的地方。如何将conta
services[0]
id=1, name="rental", ...
services[1]
id=2. name="buy", ...
services[2]
id=3. name="both", ...
等等
我已确定数组[]包含要从所选列表中检索的服务[]=1,3
foreach(var service in services.where(x=>x.id.Contains(selected))
这就是我被卡住的地方。如何将contains添加到where子句中
生成错误:未找到包含运算符请尝试在阵列上使用而不是id
foreach(var service in services.where(x => selected.Contains(x.id))
尝试在阵列上使用而不是id
foreach(var service in services.where(x => selected.Contains(x.id))