C#: How to Clone a Generic List

Found on StackOverflow, this is a tidy example of an generic extension method that uses LINQ:

[sourcecode language="c#"]
static class Extensions
    public static IList Clone(
        this IList listToClone) where T: ICloneable
        return listToClone.Select(item => (T)item.Clone()).ToList();
Be Sociable, Share!
This entry was posted in C#. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *