鉴于以下内容:
List<List<int>> lists = new List<List<int>>();
lists.Add(new List<int>() { 1,2,3,4,5,6,7 });
lists.Add(new List<int>() { 1,2 });
lists.Add(new List<int>() { 1,2,3,4 });
lists.Add(new List<int>() { 1,2,5,6,7 });
Run Code Online (Sandbox Code Playgroud)
确定所有列表中出现哪些数字的最佳/最快方法是什么?
您可以使用.net 3.5.Intersect()扩展方法: -
List<int> a = new List<int>() { 1, 2, 3, 4, 5 };
List<int> b = new List<int>() { 0, 4, 8, 12 };
List<int> common = a.Intersect(b).ToList();
Run Code Online (Sandbox Code Playgroud)