Jacob
4
Q:

list clone - C#

using System;
using System.Linq;
using System.Collections.Generic;
 
public class Example
{
    public static void Main()
    {
        List<string> source = new List<string>() { "A", "B", "C" };
 
        List<string> clonedList = source.ToList();
          Console.WriteLine(String.Join(",", clonedList));
    }
}
 
/*
    Output: A,B,C
*/
2
static class Extensions
{
    public static IList<T> Clone<T>(this IList<T> listToClone) where T: ICloneable
    {
        return listToClone.Select(item => (T)item.Clone()).ToList();
    }
}
0

New to Communities?

Join the community