【发布时间】:2011-07-19 01:08:46
【问题描述】:
可能重复:
Deep copy of 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
但我需要一份完整的副本?
【问题讨论】:
-
实际上建议不要使用 IClonable,因为它没有区分深拷贝和浅拷贝。
标签: c# c#-2.0 clone icloneable