Finding symmetric difference with LINQ

后端 未结 3 1077
心在旅途
心在旅途 2020-12-01 14:13

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 exc

3条回答
  •  甜味超标
    2020-12-01 14:51

    Given a.Except(b) and b.Except(a) are disjoint, you can use concat instead of union, saving a set operator (and concat is more efficient).

    return a.Except (b).Concat (b.Except (a));
    

    This still runs through each list twice.

提交回复
热议问题