c# - 使用linq查找不相交的数据集

标签 c# linq

List<int> a = 1,2,3
List<int> b = 2,4,5

output
1,3,4,5

最佳答案

诀窍是使用 Except与两个列表的交集。

这应该为您提供非交叉元素的列表:

var nonIntersecting = a.Union(b).Except(a.Intersect(b));

关于c# - 使用linq查找不相交的数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/712198/

相关文章:

c# - 静态资源图像在运行时不出现(在设计时出现)

javascript - JQuery "Boostrap Confirmation"插件在第二次单击时不显示

linq - Resharper 9 转换为 LINQ : method syntax

c# - 带有 linq .where 子句的空引用异常

c# - 如何手动构建将始终返回 true 的表达式?

c# - 我无法访问 x :Name of controls in ListView in XAML and Code behind

c# - ListView 选择模式无法正常运行

c# - 我可以用什么来确定相似的词或关键词?

linq - EF core 2第一次查询慢

c# - xml c# 使用 Linq 添加元素到 Xml