views:

1521

answers:

3

What's the simplest way to join one or more arrays (or ArrayLists) in Visual Basic? I'm using .NET 3.5, if that matters much.

+3  A: 

You can take a look at this thread that's titled Merging two arrays in .Net

mwilliams
+2  A: 

This is in C#, but surely you can figure it out...

int[] a = new int[] { 1, 2, 3, 4, 5 };
int[] b = new int[] { 6, 7, 8, 9, 10 };
int[] c = a.Union(b).ToArray();

It will be more efficient if instead of calling "ToArray" after the union, if you use the IEnumerable given instead.

int[] a = new int[] { 1, 2, 3, 4, 5 };
int[] b = new int[] { 6, 7, 8, 9, 10 };
IEnumerable<int> c = a.Union(b);
TheSoftwareJedi
The OP asked to join two arrays together. Not find the union which will not keep the duplicates. I do believe concat is what they might have been looking for.
uriDium
You are correct. "Join" has several meanings, but I should have understood it better.
TheSoftwareJedi
A: 

Can not add comments, so putting this in an answer.

The comment I wanted to make for the answer given by "TheSoftwareJedi" about using Union. The only thing I will be concerned over here is that Union give you only unique elements.

If you do want all the duplicate elements also then concat may be thing. And there is a previous post doing something similar.

Biswanath