开发者

Intersect a collection of collections in LINQ

开发者 https://www.devze.com 2022-12-24 17:24 出处:网络
I\'ve got a list of lists which I want to intersect: List<List<int>> 开发者_运维问答input = new List<List<int>>();

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 });

Output should be:

{ 4, 5 }

How can this be accomplished in a terse fashion?


var result = input.Cast<IEnumerable<int>>().Aggregate((x, y) => x.Intersect(y))
0

精彩评论

暂无评论...
验证码 换一张
取 消