检查两个List< INT>的为同一号码 [英] Check two List<int>'s for the same numbers

查看:216
本文介绍了检查两个List< INT>的为同一号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表的,我要检查相应的数字。

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

这篇关于检查两个List&LT; INT&GT;的为同一号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆