-2

I'm trying this solution but Copy doesn't work with array of string. and I can't change the type of the array.

Any tips?

Merging two arrays in .NET

Community
  • 1
  • 1
RollRoll
  • 8,133
  • 20
  • 76
  • 135

1 Answers1

3

Perhaps:

string[] result = arr1.Concat(arr2).ToArray();

or (if you don't want duplicates):

string[] result = arr1.Union(arr2).ToArray();

or, possibly more efficient, using Marc Gravells extension:

public static T[] Concat<T>(this T[] x, T[] y)
{
    if (x == null) throw new ArgumentNullException("x");
    if (y == null) throw new ArgumentNullException("y");
    int oldLen = x.Length;
    Array.Resize<T>(ref x, x.Length + y.Length);
    Array.Copy(y, 0, x, oldLen, y.Length);
    return x;
}
Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939