Possible Duplicate:
LINQ find differences in two lists
I want to find a difference between 2 series. So I am using Except
in the LINQ statement. But Except
seems to work only when the first collection is longer than the second. For example this will not return any result, even though the 2 collections are different.
double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };
IEnumerable<double> onlyInFirstSet = numbers2.Except(numbers1);
Can anyone confirm if this is the case? If so, do I have to check the collection lengths before I write the query, because I do not know which collection will be bigger at compile time.
Edit
I think I was not clear in my question. I do not care which collection contains what. I just want to find difference between 2 collections. How can I do this?
Except
is not symmetric. Are you looking for A.Difference(B) returning everything in A that isn't in B and everything in B that isn't in A...or are you looking for something else? – Brabant