手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#泛型序列化对象为字节数组的示例
c#泛型序列化对象为字节数组的示例
摘要:序列化对象为字节数组复制代码代码如下:usingSystem.IO;usingSystem.Runtime.Serialization.Fo...

序列化对象为字节数组

复制代码 代码如下:

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();

}

反序列化字节数组为对象

复制代码 代码如下:

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));

}

【c#泛型序列化对象为字节数组的示例】相关文章:

c#固定长度的随机字符串例子

c# dataTable 合并两个列到一个新列中的简单实例

c# 泛型类型参数与约束的深入分析

C#获取全部目录和文件的简单实例

C#垃圾回收机制的详细介绍

C# 撒列实现关键字过滤的实例

c# 生成随机时间的小例子

C# 手动/自动保存图片的实例代码

c#中抽象类和接口的详细介绍

C# 中将数值型数据转换为字节数组的方法

精品推荐
分类导航