我有一个我想要交叉的列表列表:
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 });
Run Code Online (Sandbox Code Playgroud)
输出应该是:
{ 4, 5 }
Run Code Online (Sandbox Code Playgroud)
如何以简洁的方式实现这一目标?
mqp*_*mqp 16
var result = input.Cast<IEnumerable<int>>().Aggregate((x, y) => x.Intersect(y))
Run Code Online (Sandbox Code Playgroud)