本文介绍了如何过滤掉两个列表中的常见元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何过滤掉两个列表的常用元素?
how do i filter out the common elements of two lists?
推荐答案
IEnumerable<Product> duplicates = store1.Intersect(store2);
var inBoth = firstList.Intersect(secondList);
如果你想要的值是在第一个列表中,但不是第二个:
If you want the values which are in the first list, but not the second:
var inFirst = firstList.Except(secondList);
如果你想要两个列表不常见的值:
If you want the values which are not common to both lists:
var notInBoth = firstList.Except(secondList).Union(secondList.Except(firstList));
这篇关于如何过滤掉两个列表中的常见元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!