How do I concatenate two arrays in C#?
.net, arrays, c#, linq
Solution
var z = new int[x.Length + y.Length];
x.CopyTo(z, 0);
y.CopyTo(z, x.Length);
Problem
``` int[] x = new int [] { 1, 2, 3}; int[] y = new int [] { 4, 5 }; int[] z = // your answer here... Debug.Assert(z.SequenceEqual(new int[] { 1, 2, 3, 4, 5 })); ``` Right now I use ``` int[] z = x.Concat(y).ToArray(); ``` Is there an easier or more efficient method? Be careful with the `Concat` method. The post Array Concatenation in C# explains that: ``` var z = x.Concat(y).ToArray(); ``` Will be inefficient for large arrays. That means the `Concat` method is only for meduim-sized arrays (up to 10000 elements).