Skip to content

Joining two lists together

If you have two lists of the same type, you may want to join them together. There are two ways to do this.

The first way would be to use the List.AddRange() method. This will modify the original array, so if you want to keep the original arrays, you may want to go with the second option.

List<string> a = new List<string>();
List<string> b = new List<string>();

a.AddRange(b);

The second way uses the List.Concat() method to create a new list on merging:

List<string> a = new List<string>();
List<string> b = new List<string>();

var newList = a.Concat(b);

(source)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.