简体   繁体   中英

linq return list where Contains items found

using linq: I have an object list of services

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

 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?

build error: contains operator not found

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM