If I want to filter a list of objects against a specific id, I can do this:
list.Where(r => r.Id == idToCompare);
What if, instead of a single idToCompare, I have a list of Ids to compare against?
What is the syntax for comparing against a predefined list? Something like:
int[] listofIds = GetListofIds();
list.Where(r => r.Id "in listofIds");
If
listOfIdsis a list, this will work, but, List.Contains() is a linear search, so this isn’t terribly efficient.You’re better off storing the ids you want to look up into a container that is suited for searching, like Set.