LINQ and set difference

Posted by Pierre on Stack Overflow See other posts from Stack Overflow or by Pierre
Published on 2010-05-26T05:31:18Z Indexed on 2010/05/26 5:41 UTC
Read the original article Hit count: 353

Filed under:
|
|

I have two collections a and b. I would like to compute the set of items in either a or b, but not in both (a logical exclusive or). With LINQ, I can come up with this:

IEnumerable<T> Delta<T>(IEnumerable<T> a, IEnumerable<T> b)
{
    return a.Except (b).Union (b.Except (a));
}

I wonder if there are other more efficient or more compact ways of producing the difference between the two collections.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ