我有两个表的,我要检查相应的数字。
I have two List's which I want to check for corresponding numbers.
例如
List<int> a = new List<int>(){1, 2, 3, 4, 5};
List<int> b = new List<int>() {0, 4, 8, 12};
应该给4的结果。 有没有一种简单的方法来做到这一点,而无需通过列表太多的循环?
Should give the result 4. Is there an easy way to do this without too much looping through the lists?
我在3.0,我需要这个所以没有LINQ的项目。
I'm on 3.0 for the project where I need this so no Linq.
您可以使用.NET 3.5 .Intersect()扩展方法: -
You can use the .net 3.5 .Intersect() extension method:-
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();
上一篇:在哪里可以找到.NET版本的使用统计?可以找到、版本、NET
下一篇:在Visual Studio 2015年的IFormatProvider(CA1305)字符串插值字符串、插值、Studio、Visual