欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#泛型序列化對象為字節(jié)數(shù)組的示例

 更新時間:2014年04月22日 10:43:29   作者:  
這篇文章主要介紹了c#泛型序列化對象為字節(jié)數(shù)組的示例,需要的朋友可以參考下

序列化對象為字節(jié)數(shù)組

復(fù)制代碼 代碼如下:

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ù)組為對象

復(fù)制代碼 代碼如下:

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)文章

最新評論