This tutorial will discuss methods to add one list’s elements at the end of another list in C#.

Add a List to Another List With the List.AddRange() Function in C#

The easiest method for appending one list’s elements at the end of the other list is to use the List.AddRange() method in C#. The List.AddRange(x) method adds the elements of the collection x in the list. The following code example shows us how to add one list to another list with the List.AddRange() function in C#.

using System; using System.Collections.Generic; namespace add_list { static void Main(string[] args) { List<string> first = new List<string> { "do", "rey", "me" }; List<string> second = new List<string> { "fa", "so", "la", "te" }; first.AddRange(second); foreach(var e in first) { Console.WriteLine(e); } } } }

Output:

do rey me fa so la te

We created and initialized 2 lists of strings, first and second, in the above code. We appended the second list elements at the end of the first list with the first.AddRange(second) function. In the end, we displayed the elements of the first list.

DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Csharp List

  • Get the Last Element of a List in C#
  • Iterate Through a List in C#