"SmallClass"라는 C# 클래스가 있습니다.딥 클론 c의 개체 목록
나는 유형 "SmallClass"
내가 목록 "으로 myList"의 깊은 복제를 원하는의 객체를 포함하고있는 기존 목록으로 myList 있습니다. 즉, 포함 된 목록을 복제하고 목록에 포함 된 개체를 깊이 복제합니다.어떻게해야합니까?
public class SmallClass: ICloneable {
public string str1;
public string str2;
public string str3;
public SmallClass Clone() //This just deep clones 1 object of type "SmallClass"
{
MemoryStream m = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
b.Serialize(m, this);
m.Position = 0;
return (SRO)b.Deserialize(m);
}
public override equals(Object a)
{
return Object.Equals(this.str1 && a.str1);
}
}
public class AnotherClass
{
SomeCode();
List<SmallClass> myList = new List<SmallList>(); //myList is initialized.
// NOW I want to deep clone myList. deep Clone the containing list and deep clone the objects contained in the list.
List<SmallClass> newList = new List<SmallClass>();
foreach(var item in myList)
{
newList.Add((SmallClass)item.Clone());
}
은}
여기 무슨 일이야? ' – climbage