I'm wondering if Linq has a method to check if two collections have at least a single element in common. I would expect something like this:
var listA = new List<int>() { some numbers };
var listB = new List<int>() { some numbers, potentially also in list A };
bool hasSameElements = listA.hasMatchingElements(listB);
Does it exists in Linq or should I write a custom method for it?
I am aware of the Intersect method, but doesn't this yield the entire intersection set? I'm only interested in checking IF the two collection intersect, yielding the entire set seems like a waste, especially on larger collections.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…