HOWTO · Csharp

How to Add List to Another List in C#

Learn how to add one list to another in C#

On this page

To append the elements of one C# List<T> to another, call AddRange on the list that should receive them. The generic collection type is List<T>, where T represents the element type. The source elements are added after the destination’s existing elements, in their original order. AddRange changes the destination; it does not add the source list as a nested element. Use this method when both collections contain compatible element types. A List<T> stores elements of one type, so choose a matching destination and source.

How to Add One List to Another in C#

List<T> is a resizable collection whose elements share the same type T. In this example, both lists contain integers. The System.Collections.Generic namespace provides List<T>, so include it if your project does not already import that namespace. The program appends the second list to the first, then prints the resulting destination list:

The generic type notation is List<T>; replace T with the element type shared by every item, such as int.

Run this complete example:

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<int> firstList = new List<int> { 1, 2, 3 };
        List<int> secondList = new List<int> { 4, 5, 6 };

        firstList.AddRange(secondList);

        Console.WriteLine(string.Join(", ", firstList));
    }
}
1, 2, 3, 4, 5, 6

The call appends the values from secondList after the values already in firstList; the destination remains a flat List<int>. Both lists must have compatible element types. For example, a List<int> cannot receive strings from a List<string> through this call. Convert or map elements first if the destination needs a different type.

Append One List with List.AddRange

AddRange is an instance method on List<T>. Call it on the destination and pass a collection that supplies elements of the same T. Its parameter is IEnumerable<T>, so the source can be an array or another compatible sequence; it does not have to be another List<T>. For example, firstList.AddRange(secondList) appends the source sequence to the end of firstList.

The method enumerates the source and appends its elements in sequence order. After the call, firstList contains its original values followed by the values from secondList, while secondList retains its own elements. This distinction matters when later code still needs the source collection. If you need to preserve the destination too, call AddRange on a separate list as shown in the next section.

Keep the Original Lists Unchanged

To combine two inputs without changing either one, create a new destination from the first list and append the second list to it: List<int> combined = new List<int>(firstList); followed by combined.AddRange(secondList);. The constructor copies the first input’s elements into a new list, and the method changes only that new destination. Use combined for the joined sequence; the original lists remain available in their prior state.

This is a shallow copy. It copies the list structure and element references, not the objects referenced by the elements. For value types such as int, the values are copied into the new list. For reference types, the new list and the original list still point to the same objects. If those objects are mutable and need independent state, create copies of the objects as well.

Add Lists of Custom Objects

AddRange also works with custom classes when the source elements can be stored in the destination. For example, if people and peopleToAdd are both List<Person>, calling people.AddRange(peopleToAdd) places each person after the existing entries. You can then iterate over people and read a property such as person.Name to display or process them.

The method appends references to the existing Person instances; it does not clone the objects. Changing a mutable person through either list is visible through the other list because both lists refer to that same instance. The same approach applies to other custom types, such as products or user records, provided their element types are compatible with the destination’s T.