How to Intersect two Arrays?

纵然是瞬间 提交于 2020-01-24 13:30:11

问题


I'm working with VB.Net, and have two one-dimensional Arrays. Is there an Inbuilt function for finding the elements that are common to both of them? Or do I have to write one for myself?


回答1:


I'm afraid you'll have to write one for yourself, because there is no built-in function in .NET 2.0.

Look at this StackOverflow question for ideas about how you could implement it yourself.




回答2:


If you can use the LINQ extension methods (VB9), then yes - you can use Enumerable.Intersect():

dim a as String() = {"blah", "bleak", "blorg", "blue"}
dim b as String() = {"blaah", "bleak", "bleee", "blue"}

' c will contain "blah" and "blue" '
dim c as IEnumerable(Of String) = a.Intersect(b)



回答3:


Just use LinqBridge for .net 2.0 http://code.google.com/p/linqbridge/downloads/list and you should be able to use the intersect method.



来源:https://stackoverflow.com/questions/982174/how-to-intersect-two-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!