我正在使用VB.Net,并且有两个一维数组。是否有一个内置函数来查找两个元素共有的元素?还是我必须为自己写一个?
恐怕您必须自己编写一个,因为.NET 2.0中没有内置函数。
查看this StackOverflow question,了解有关如何自己实现的想法。
如果可以使用LINQ扩展方法(VB9),则可以-可以使用Enumerable.Intersect()
:
Enumerable.Intersect()
只需将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)
,就应该能够使用相交方法。