Determine if two collections share at least one element

c#, linq

Solution

You can use the Any().

var listA = new List<int>();
var listB = new List<int>();

bool hasCommonItem = listA.Any(i => listB.Contains(i));

Moreover, you can write an IEqualityComparer implementation to pass it as a parameter to the Contains() if necessary.

Problem

Is there a way to determine if a collection contains at least one element from another collection?

Original source

Related problems