using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace jquery
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int i = 10;
i=DeepCloneObject<int>.DeepClone(i);
}
}
/// <summary>
/// 实现深拷贝
/// </summary>
/// <typeparam name="T">类型</typeparam>
public static class DeepCloneObject<T>
{
public static T DeepClone(T param)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, param);
memoryStream.Position = 0;
return (T)formatter.Deserialize(memoryStream);
}
}
}