I have a generic list of objects in C#, and wish to clone the list. The items within the list are cloneable, but there doesn\'t seem to be an option to do list.Clone()
Unless you need an actual clone of every single object inside your List
, the best way to clone a list is to create a new list with the old list as the collection parameter.
List myList = ...;
List cloneOfMyList = new List(myList);
Changes to myList
such as insert or remove will not affect cloneOfMyList
and vice versa.
The actual objects the two Lists contain are still the same however.