我的名字:“周末” 程序猿/轻设计/轻生活/轻日记/轻梦想 === 微信:zhoumojianshe ===
© 优特良品&优特建站出品 | Powered by YOUTIY
苏ICP备13018047号-1
C#实现对象的深拷贝
TAGS: 后端设计
	/// <summary>
	/// 实现对象的深拷贝
	/// </summary>
	/// <typeparam name="T">对象类型</typeparam>
	/// <param name="obj">对象</param>
	/// <returns>T</returns>
	public static T CreateDeepCopy<T>(T obj)
	{
		T t;
		MemoryStream memoryStream = new MemoryStream();
		BinaryFormatter formatter = new BinaryFormatter();
		formatter.Serialize(memoryStream, obj);
		memoryStream.Position = 0;
		t = (T)formatter.Deserialize(memoryStream);
		return t;
	}

调用方法:

CategoryInfo category = CreateDeepCopy<CategoryInfo>((CategoryInfo)bsCategory.Current);

周末
2021-11-22 22:13:55
标签云
网页设计 精致慢生活 感悟思语 我的旧年华
加偶微信