用于深拷贝的扩展方法 C#

it2022-07-05  145

using System.Runtime.Serialization.Formatters.Binary; using System.IO; public static class Tool { public static T DeepCopy<T>(this T obj) { BinaryFormatter formatter = new BinaryFormatter(); Stream stream=new MemoryStream(); formatter.Serialize(stream, obj); stream.Position = 0; T returnObj = (T)formatter.Deserialize(stream); return returnObj; } }

 

转载于:https://www.cnblogs.com/kotomi/p/8135291.html

相关资源:C#微软培训资料

最新回复(0)