在C#中的多个列表中查找常用项目 [英] find common items across multiple lists in C#
本文介绍了在C#中的多个列表中查找常用项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个通用列表:
列表< string> TestList1 =新列表< string>();
列表< string> TestList2 =新列表< string>();
TestList1.Add(1);
TestList1.Add(2);
TestList1.Add(3);
TestList2.Add(3);
TestList2.Add(4);
TestList2.Add(5);
在这些列表中找到共同项目的最快方法是什么?
假设你使用一个带有LINQ的.Net版本,你可以使用Intersect扩展方法:
pre> var CommonList = TestList1.Intersect(TestList2)
I have two generic list :
List<string> TestList1 = new List<string>();
List<string> TestList2 = new List<string>();
TestList1.Add("1");
TestList1.Add("2");
TestList1.Add("3");
TestList2.Add("3");
TestList2.Add("4");
TestList2.Add("5");
What is the fastest way to find common items across these lists?
解决方案
Assuming you use a version of .Net that has LINQ, you can use the Intersect extension method:
var CommonList = TestList1.Intersect(TestList2)
这篇关于在C#中的多个列表中查找常用项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文