Deep copy and shallow copy with List<> [modified]
-
Hello, I'm using C# 2.0 generics in an application I'm writing and I have a question about copying one list to another. The List<> generic doesn't seem to have a deep copy method. It has CopyTo() but this copies to an array, not to a List<>. Suppose I have a large list of objects: main() { List original = new List(); // add 10000 MyClass objects to original... // ...... List backup = new List(); ShallowCopy(original, backup); } static void ShallowCopy(List source, List dest) { dest.Clear(); foreach(T t in source) { dest.Add(t); } } OK, this gives me a shallow copy, but what if I want a deep copy? It doesn't look like there's a deep copy built into generics... or what am I missing? Thanks, Jeff -- modified at 17:27 Wednesday 7th February, 2007