Reputation: 51937
I have an object model MyObject
that contains a list of long called ObjectList
. I have another list called TestList
that also contains longs and I want to determine if TheObject.ObjectList
contains any elements that are in TestList
.
I'm trying with something like this but it's not giving Count as an option.
if (TheObject.ObjectList.Any(TestList).Count() > 0) {...}
How should I rewrite this? Thanks for your suggestions.
Upvotes: 2
Views: 700
Reputation: 499002
Use Intersect
:
TheObject.ObjectList.Intersect(TestList).Any()
Produces the set intersection of two sequences by using the default equality comparer to compare values.
Note: There are also Except
and Union
set opeartions.
Upvotes: 5
Reputation: 273244
if ( TheObject.ObjectList.Intersect(TestList).Any() )
{
...
}
Upvotes: 3