获得从泛型列表对称差 [英] Get the symmetric difference from generic lists

查看:140
本文介绍了获得从泛型列表对称差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张表,我需要比较两个并得到一切的的两个列表的交集。我怎样才能做到这一点(C#)?

I have 2 separate List and I need to compare the two and get everything but the intersection of the two lists. How can I do this (C#)?

推荐答案

您可以使用的除了得到一切,但路口两表中。

You can use Except to get everything but the intersection of the two lists.

var differences = listA.Except(listB).Union(listB.Except(listA));

如果你想获得的一切,但在联合

If you want to get everything but the union:

var allButUnion = new List<MyClass>();

(工会是一切都在这两个列表 - 一切,但工会是空集......)

(The union is everything in both lists - everything but the union is the empty set...)

这篇关于获得从泛型列表对称差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆