简体   繁体   中英

How to filter or query an object collecting based upon an array in C# Linq

I have a C# collection of custom objects, say BookUsers, which has UserID as one of the property. I have a string array of UserID's in a separate variable. I want to get the subset of the BookUsers collection filtered by the UserID's in the string array. Please let me know how to do this using Linq.

Thanks

bookusers.Where(b=>ids.Contains(b.UserId))

您可能需要考虑将用户ID数组放入HashSet中,以减少内部查询的复杂性。

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