I’m guessing it does NOT, but if someone could confirm.
If I try to intersect two sets:
A (1 million items)
B (1 item)
Does the framework always do A.Contains(B) once, instead of B.Contains(A) one million times?
This is assuming that’s how intersects work beneath the hood, as opposite to some fancy algorithm I am not aware of.
UPDATE:
OK so for c# you should clearly do B.InsersectWith(A), if B << A. Intersect() is defined on IEnumerable and would be a lot less efficient based on the answers below (and MSDN). So the order does matter if you use the best tool, which is IntersectWith().
From the documentation
If the collection represented by the other parameter is a HashSet collection with the same equality comparer as the current HashSet object, this method is an O(n) operation. Otherwise, this method is an O(n + m) operation, where n is Count and m is the number of elements in other.
HashSet.IntersectWith Method
And if you are looking for speed implement (override) GetHashCode if you can derive a meaningful Hash from your data. And override Equal. I do this for any class that will be in a collection.
Object.GetHashCode Method