/// <summary> /// 深度复制 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <returns></returns> private static T DeepCopyByBin<T>(T obj) { object retval; using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); //序列化成流 bf.Serialize(ms, obj); ms.Seek(0, SeekOrigin.Begin); //反序列化成对象 retval = bf.Deserialize(ms); ms.Close(); } return (T)retval; }
标签:bf,MemoryStream,c#,BinaryFormatter,复制,ms,深度,retval From: https://www.cnblogs.com/nayilvyangguang/p/16897098.html