Possible Duplicate:
How do I clone a generic list in C#?
List<MyObject> a1 = new List<MyObject>();
var new1 = a1;
Now if I change a1 then new1 is going to be changed as well.
So my question is how to make a clone of a1 correctly?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This wont
Cloneeach item in the list but will create you a new listIf you want to clone each Item in the list you can implement
ICloneableonMyObjectEDIT:
To make it a bit clearer both will copy the elements from list
a1into a new list. You just need to decide if you want to have newMyObjects or keep the originals. If you want to cloneMyObjectyou will need a way to clone them which typically is done throughICloneable.