HOWTO · Csharp

How to Copy a List in C#

In this article, we will explore different techniques for copying lists in C# and discuss their use cases, advantages, and implementation details.

On this page

To copy a C# list, use new List<T>(source) or LINQ’s source.ToList() to create a separate list with the same elements. Both make a shallow copy: they do not create new objects for reference-type elements. Use AddRange to append elements to a destination, GetRange to copy a segment, and explicit element-copying logic when the objects themselves must be independent.

Shallow Copy vs. Deep Copy

A list contains slots for its elements. Copying the list creates a new set of slots, so adding or removing an element in one list does not change the other list’s structure. What happens to each element depends on its type.

For value types such as int, each list holds its own value. For reference types such as a custom Person class, each list holds a reference. A shallow copy duplicates those references, so both lists point to the same objects. Changing a reference-type object’s properties through either list is visible through the other; replacing or removing a slot in one list does not replace or remove the corresponding slot in the other.

A deep copy also creates independent copies of the referenced objects. That requires a copying rule for the element type; none of the standard list-copy methods can infer how an arbitrary object and its nested state should be duplicated.

Copy a List in C# Using the List Constructor

The list constructor is a direct way to create a new list from an existing collection. This example uses strings and shows the basic copy operation.

Run this example:

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var original = new List<string> { "Laptop", "Desktop", "Tablet" };
        var copy = new List<string>(original);

        original.Add("Phone");
        Console.WriteLine(string.Join(", ", copy));
    }
}

The constructor enumerates the source elements into a new list. In this example, copy retains the three original entries when another entry is added to original. For a list of reference-type elements, the new list still contains the same object references. The constructor accepts collections of value or reference types; it is not limited to value-type lists.

Copy a List in C# Using LINQ ToList

LINQ’s ToList() materializes an IEnumerable<T> as a new List<T>. It is useful when the source is a query or another enumerable, as well as when it is already a list. Include using System.Linq; to use the extension method.

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        IEnumerable<string> source = new[] { "Chair", "Table", "Couch" };
        List<string> copy = source.ToList();
        Console.WriteLine(string.Join(", ", copy));
    }
}

ToList() creates a new container and copies the elements yielded by the enumerable. If those elements are references to mutable objects, the copied list contains the same references; use an element-specific copying operation when that sharing is undesirable.

Copy a List in C# Using List<T>.AddRange

AddRange appends every element from an IEnumerable<T> to the end of the list on which it is called. To make a copy, create the destination list first and then append the source elements:

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var original = new List<string> { "Chair", "Table", "Couch" };
        var copy = new List<string>();
        copy.AddRange(original);
        Console.WriteLine(string.Join(", ", copy));
    }
}

The destination starts without elements here, so after AddRange it contains the source sequence. If the destination already has elements, they remain before the appended items; AddRange does not replace its contents. Like the constructor, it copies element values or references, not the objects behind reference-type elements.

Copy a Portion of a List Using List<T>.GetRange

Use GetRange(index, count) to create a new list containing a consecutive segment. The index is zero-based, and the count is the number of elements to include. For example, index 1 and count 3 select the second, third, and fourth elements:

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var original = new List<string> { "Chair", "Table", "Couch", "Lamp", "Rug" };
        List<string> segment = original.GetRange(1, 3);
        Console.WriteLine(string.Join(", ", segment));
    }
}

The requested range must fit within the source list: the index and count must be nonnegative, and their sum cannot exceed the list’s count. Otherwise, GetRange throws an ArgumentOutOfRangeException. The returned list is a new container, but reference-type elements in the segment still refer to the same objects as the source list.

Create a Deep Copy of List Elements

There is no universal item.Clone() method for arbitrary C# objects, and implementing ICloneable does not guarantee that Clone() performs a deep copy. A type may expose its own copy constructor or method, but its documented behavior determines which nested objects are copied.

For a known type, express the desired copying rule directly. For example, if Person has a constructor that copies all relevant fields and creates any needed independent nested objects, a list can be copied with people.Select(person => new Person(person)).ToList(). This requires using System.Linq; and the Person(Person other) constructor to be implemented by the application. That constructor must decide how to copy each member; copying a nested reference directly would preserve sharing for that member.

Choose a strategy based on the data model: immutable objects can often be shared safely, while mutable objects that must be independent need explicit element-copying logic. Check the type’s copy contract rather than assuming a method named Clone duplicates its entire object graph.

Choose a List-Copying Method

  • Use new List<T>(source) for a clear, direct copy from a collection.
  • Use source.ToList() when materializing an enumerable or when the LINQ form fits the surrounding query.
  • Use destination.AddRange(source) when the goal is to append source elements to a destination; start with a new destination if it should contain only the copied sequence.
  • Use source.GetRange(index, count) for a contiguous portion, ensuring the requested range fits the source.
  • Use explicit element-copying logic when reference-type objects must be independent. A new list alone only separates the list structure.