ShadowClone
对象内部嵌套的引用成员仍是指向原对象内部的引用成员。
DeepClone
对象内嵌套的引用成员也被创建了一个
public Class1 ShadowClone()
{
return (Class1)this.MemberwiseClone();
}
public Class1 DeepClone()
{
using (System.IO.MemoryStream sm = new System.IO.MemoryStream())
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryformatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryformatter.Serialize(sm, this);
sm.Seek(0, System.IO.SeekOrigin.Begin);
object ob = binaryformatter.Deserialize(sm);
return (Class1)ob;
}
}
对象内部嵌套的引用成员仍是指向原对象内部的引用成员。
DeepClone
对象内嵌套的引用成员也被创建了一个
public Class1 ShadowClone()
{
return (Class1)this.MemberwiseClone();
}
public Class1 DeepClone()
{
using (System.IO.MemoryStream sm = new System.IO.MemoryStream())
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryformatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryformatter.Serialize(sm, this);
sm.Seek(0, System.IO.SeekOrigin.Begin);
object ob = binaryformatter.Deserialize(sm);
return (Class1)ob;
}
}