Search code examples
c#listexcept

List.Except returns only 1 item when there are several in the diff set


In C# trying to do an Except between two lists of strings. There are some diff's, see the image below. At idx 2 and 19 note these are not the same. yet the List.Except method is only returning the last difference.

I call it like this: var x = expList.Except(actList);

Returns 1 item in the result: "site".

I expect 2 items: 4001, "site"

Anyone have any ideas as to what's going on here?

Thanks!

Lists


Solution

  • As Alexei Levenkov mentioned, Enumerable.Except is not a "symmetric difference".

    Consider:

    new HashSet<string>(expList).SymmetricExceptWith(actList);