





























引用类型的对象复制,分为浅复制和深复制。。。
浅复制就简单的把地址复制给另一个对象,其中有一个对象发生变化,2个都有变化。
实现方式,实现 ICloneable 接口,调用 MemberwiseClone()方法就可以了。
深复制就完全产生一个新的对象,二者属性一样,但没有任何关联。。
实现方式,可以重新 new 一个对象,也可以通过序列化、反序列化来实现。。
代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace H.DBF
{
///
///
<summary> bf.Serialize(ms, this);
ms.Seek(0, SeekOrigin.Begin);
obj = bf.Deserialize(ms);
ms.Close();
return obj;
}
//ObjBase obj = (ObjBase) System.Activator.CreateInstance(this.GetType());
//obj.TableName = this.TableName;
//obj.Columns = this.Columns;
//return obj;
}
#endregion
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。