如何相交两个数组?

问题描述 投票:2回答:3

我正在使用VB.Net,并且有两个一维数组。是否有一个内置函数来查找两个元素共有的元素?还是我必须为自己写一个?

vb.net arrays intersection
3个回答
1
投票

恐怕您必须自己编写一个,因为.NET 2.0中没有内置函数。

查看this StackOverflow question,了解有关如何自己实现的想法。


9
投票

如果可以使用LINQ扩展方法(VB9),则可以-可以使用Enumerable.Intersect()

Enumerable.Intersect()

1
投票

只需将LinqBridge用于.net 2.0 dim a as String() = {"blah", "bleak", "blorg", "blue"} dim b as String() = {"blaah", "bleak", "bleee", "blue"} ' c will contain the intersection, "bleak" and "blue" ' dim c as IEnumerable(Of String) = a.Intersect(b) ,就应该能够使用相交方法。

© www.soinside.com 2019 - 2024. All rights reserved.