Assuming LINQ to objects (i. e. these are in-memory collections not LINQ to Entities IQueryables or something):
Will statement 2. call GetMyListB() for each item in ListA?
Yes. If you want to avoid this, you'll have to store the result of GetMyListB() outside the function.
Which is more readable?
In my opinion two are about equally readable, although I would change #2 to be:
bool overlap = GetMyListA().Any(GetMyListB().Contains); // 2.
As far as performance, #1 will probably perform better in most cases, since it will dump all of one list into a hash table and then do an O(1) lookup for each element in the other list. Two exceptions to this that I can think of are (1) if the lists are very small, then building the hash table data structure might not be worth the overhead and (2) option 2 can theoretically return without having considered every element in either list. If the lists are large lazy enumerables and you expect this to return true in most cases then this could lead to a performance increase.
GetMyListA()orGetMyListB()). I'd say 1 is the most readable and 2 the most logical. – Jeff Mercado Jun 27 '12 at 15:10Intersect()would utilize hash sets to determine uniqueness. The other code would perform linear searches through list B and would return on the first match (and yes,GetMyListB()will be called for each item in list A). – Jeff Mercado Jun 27 '12 at 15:40