Does C# have a ContainsAny() method for a dictionary?

c#, collections, linq

Solution

Yes, you can try this for lists:

people = people.Where(r => list.Intersect(r.CarIds).Count() != 0).ToList();

For dictionaries, you can use this:

people = people.Where(r => r.CarIds.Any(n => dictionary.ContainsKey(n))).ToList();

Problem

I have a dictionary where the Key is an Id and the value is a string I now have a List of person objects where each person has a CarIds property that is an ``` IEnumerable<int> ``` I want to basically filter the list of objects to only include items where one of the properties is included in the dict. For example. something like this: ``` var dictionary = GetDict(); var people = GetPeople(); people = people.Where(r => dictionary.ContainsAny(r.CarIds)).ToList(); ``` Does something like this exist where I can do something similar to ContainsKey() but check for any in a list of ints ?

Original source