c#泛型序列化對象為字節(jié)數(shù)組的示例
更新時間:2014年04月22日 10:43:29 作者:
這篇文章主要介紹了c#泛型序列化對象為字節(jié)數(shù)組的示例,需要的朋友可以參考下
序列化對象為字節(jié)數(shù)組
復制代碼 代碼如下:
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();
}
反序列化字節(jié)數(shù)組為對象
復制代碼 代碼如下:
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));
}
相關(guān)文章
基于Silverlight DataGrid中無代碼設(shè)置開始與結(jié)束日期DatePicker的實現(xiàn)方法
本篇文章是對Silverlight DataGrid中無代碼設(shè)置開始與結(jié)束日期DatePicker的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05
C#中List〈string〉和string[]數(shù)組之間的相互轉(zhuǎn)換
List<string>和string[]數(shù)組之間的相互轉(zhuǎn)換,需要的朋友可以參考下2012-12-12
C#保存listbox中數(shù)據(jù)到文本文件的方法
這篇文章主要介紹了C#保存listbox中數(shù)據(jù)到文本文件的方法,涉及C#操作listbox數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2015-04-04

