源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#泛型序列化对象为字节数组的示例

  • 时间:2022-07-14 13:19 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#泛型序列化对象为字节数组的示例
序列化对象为字节数组
[u]复制代码[/u] 代码如下:
using System.IO; using System.Runtime.Serialization.Formatters.Binary;         protected byte[] Serialize<T>(T t)         {             MemoryStream mStream = new MemoryStream();             BinaryFormatter bFormatter = new BinaryFormatter();             bFormatter.Serialize(mStream, t);             return mStream.GetBuffer();         }
反序列化字节数组为对象
[u]复制代码[/u] 代码如下:
using System.IO; using System.Runtime.Serialization.Formatters.Binary;         protected T Deserialize<T>(byte[] b)         {             BinaryFormatter bFormatter = new BinaryFormatter();             return (T)bFormatter.Deserialize(new MemoryStream(b));         }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部