.net core list copy code example

Example 1: list clone - C#

static class Extensions
{
    public static IList<T> Clone<T>(this IList<T> listToClone) where T: ICloneable
    {
        return listToClone.Select(item => (T)item.Clone()).ToList();
    }
}

Example 2: copy a list C#

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

List<string> source = new List<string>() { "A", "B", "C" };
 
List<string> clonedList = source.ToList();
Console.WriteLine(String.Join(",", clonedList));

// Result = A,B,C

Example 3: c# copy the elements of a list to another list

List<Int32> copy = new List<Int32>(original);
List<Int32> copy = original.ToList(); // if you're using C# 3 and .NET 3.5, with Linq