views:

416

answers:

3

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?

+6  A: 

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)
Shog9
+1 for this, OP should be aware however that this is a VB9.0 solution, if he is using VB8.0 (Visual Studio 2005) this won't work for him.
Patrick McDonald
@Patrick: good point, noted
Shog9
Unfortunately, I'm still working with VB8.0 with 2.0 .NET framework, so looks like I'm out of luck
dev
+1  A: 

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.

Meta-Knight
A: 

I ended up writing my own Routine for it. I basically used Nested loops.

dev