您的位置:首页 > 其它

Deep Clone

2009-10-13 20:02 155 查看
Have you ever used the Clone() method of DataSet? This method creates an empty class with same structure as original DataSet.
You can write your own clonable classes. To do so, you must implement IClonable. The following code shows a clonable Test class.

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public Class Test : IClonable

{

public Test()

{

}

// deep copy in separeate memory space

public object Clone()

{

MemoryStream ms = new MemoryStream();

BinaryFormatter bf = new BinaryFormatter();

bf.Serialize(ms, this);

ms.Position = 0;

object obj = bf.Deserialize(ms);

ms.Close();

return obj;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: