可能重复:
List<T> 的深拷贝
public class MyClass : ICloneable
{
private List<string> m_list = new List<string>();
public MyClass()
{
List.Add("1111");
List.Add("2222");
List.Add("3333");
List.Add("4444");
}
public List<string> List
{
get { return m_list; }
set { m_list = value; }
}
public object Clone()
{
return this.MemberwiseClone();
}
}
例子:
MyClass m = new MyClass();
MyClass t = (MyClass)m.Clone();
m.List.Add("qweqeqw");
//m.List.Count == 5
t.ToString();
//t.List.Count==5
但我需要一份完整的副本如何做到这一点?