How to find if an element of a list is in another list?
It seems odd to critique the performance of LINQ when the original is clearly (worst case) O(n*m); the LINQ approach would I expect use a HashSet<T>
on a list, and then use a streaming iterator block - so the performance should be O(n+m) - i.e. better.
The second one has better performance on large lists than the first one. Intersect
puts the elements of one list into a hash table before checking the other list's elements for membership.