c#深度克隆

来源:互联网 发布:c语言如何求最小公倍数 编辑:程序博客网 时间:2024/06/06 14:13

深度克隆的方法,用序列化

using System.Xml.Serialization;using System.IO;using System.Runtime.Serialization.Formatters.Binary; public object Clone()       {           MemoryStream stream = new MemoryStream();           BinaryFormatter formatter = new BinaryFormatter();           formatter.Serialize(stream, this);           stream.Position = 0;           return formatter.Deserialize(stream);       }


原创粉丝点击