2

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?

Devdatta Tengshe
  • 4,015
  • 10
  • 46
  • 59
  • similar question is at: http://stackoverflow.com/questions/245557/algorithm-to-find-if-two-sets-intersect But it does not answer my question – Devdatta Tengshe Jun 11 '09 at 16:32

3 Answers3

9

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 the intersection, "bleak" and "blue" '
dim c as IEnumerable(Of String) = a.Intersect(b)
dpatchery
  • 508
  • 5
  • 19
Shog9
  • 156,901
  • 35
  • 231
  • 235
1

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.

firematta
  • 13
  • 4
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.

Community
  • 1
  • 1
Meta-Knight
  • 17,626
  • 1
  • 48
  • 58