This post will discuss how to concatenate two arrays in C#. The solution should contain all the elements of the first array, followed by all the second array elements.

1. Using Enumerable.Concat() method

The Enumerable.Concat() method provides a simple way to concatenate multiple arrays in C#. The following example demonstrates the usage of the Concat() method by concatenating two arrays.

Download  Run Code

2. Using Array.CopyTo() method

The Array.CopyTo() method provides a convenient and efficient way to copy an array in C#. We can use this method for copying all elements of the given arrays into an empty array, as shown below:

Download  Run Code

3. Using AddRange() method

We can use the AddRange() method to add the specified array elements at the end of the List<T>. Here’s what the code would look like:

Download  Run Code

 
The above code can be shortened to a single AddRange() call as follows:

Download  Run Code

4. Using Array.Resize with Array.Copy

Finally, if you need to merge the second array into the first array, we can resize the first array using the Array.Resize() method and then use Array.Copy to copy elements from the second array to the first array.

Download  Run Code

That’s all about concatenating two arrays in C#.