比较列表联合

本文关键字:列表 比较 | 更新日期: 2023-09-27 18:14:03

List<String> A = new List<String>();
List<String> B = new List<String>();
List<String> itemsremoved = ((A∩B)^c)-A;
List<String> itemsadded = ((A∩B)^c)-B;

我想知道如何做并集a &B减去一个列表的元素。有这样的函数吗?

比较列表联合

LINQ提供了处理集合的扩展方法。

例如,集合a相对于集合b的补集为:

var a = new List<int> { 1, 2, 3, 6 };
var b = new List<int> { 3, 4, 5, 6 };
var comp = a.Except(b);

comp将包含元素[1, 2]

在Google上搜索一下c#和LINQ集合操作,你肯定能找到很多例子。