与LINQ中的集合相交 [英] Intersect a collection of collections in LINQ
本文介绍了与LINQ中的集合相交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要交集的清单清单:
I've got a list of lists which I want to intersect:
List<List<int>> input = new List<List<int>>();
input.Add(new List<int>() { 1, 2, 4, 5, 8 });
input.Add(new List<int>() { 3, 4, 5 });
input.Add(new List<int>() { 1, 4, 5, 6 });
输出应为:
{ 4, 5 }
这如何以简洁的方式完成?
How can this be accomplished in a terse fashion?
推荐答案
var result = input.Cast<IEnumerable<int>>().Aggregate((x, y) => x.Intersect(y))
这篇关于与LINQ中的集合相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文