How to make correct clone of the List? [duplicate]

This wont Clone each item in the list but will create you a new list

var new1 = new List<MyObject>(a1);

If you want to clone each Item in the list you can implement ICloneable on MyObject

var new1 = new List<MyObject>(a1.Select(x => x.Clone()));

EDIT:
To make it a bit clearer both will copy the elements from list a1 into a new list. You just need to decide if you want to have new MyObjects or keep the originals. If you want to clone MyObject you will need a way to clone them which typically is done through ICloneable.

Leave a Comment