c#如何将object类型序列化为二进制存入SQLSERVER中,并从数据库中读出来并反序列化得到object对象 10
2个回答
展开全部
///<summary> ///
序列化
/// </summary> ///
<param name="data">要序列化的对象</param>
/// <returns>返回存放序列化后的数据缓</returns>
public static byte[] Serialize(object data)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream rems = new MemoryStream();
formatter.Serialize(rems, data);
return rems.GetBuffer();
}
/// <summary> /// 反序列化 /// </summary>
/// <param name="data">数据缓冲区</param>
/// <returns>对象</returns>
public static object Deserialize(byte[] data)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream rems = new MemoryStream(data);
data = null; return formatter.Deserialize(rems);
}
序列化
/// </summary> ///
<param name="data">要序列化的对象</param>
/// <returns>返回存放序列化后的数据缓</returns>
public static byte[] Serialize(object data)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream rems = new MemoryStream();
formatter.Serialize(rems, data);
return rems.GetBuffer();
}
/// <summary> /// 反序列化 /// </summary>
/// <param name="data">数据缓冲区</param>
/// <returns>对象</returns>
public static object Deserialize(byte[] data)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream rems = new MemoryStream(data);
data = null; return formatter.Deserialize(rems);
}
展开全部
可以看看我发的资源http://download.csdn.net/detail/luyugao/5778155,
先序列化成二级制,加密了的,
先序列化成二级制,加密了的,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询