简体   繁体   中英

How to find List of objects inside list of integers

I have a List of object List and ObjectA contains a parameter integer Id and I do also have a list of integers List.

I need to find all the objects whose Id contains inside list of integers. I am trying to use Linq but can't find right query. Tried where or find but can't come up with a good query.

objectALists.Where(x => x.Id.In(intIds))....

You just need Contains with a Where clause:

objectList.Where(x => idList.Contains(x.Id)).ToList();

If your object list is a List<T> you can also use FindAll method with a predicate:

objectList.FindAll(x => idList.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