Serialization in C# without using file system
原文:http://stackoverflow.com/questions/302821/serialization-in-c-without-using-file-system
public static byte[] Serialize<T>(T t) {
IFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream()) {
formatter.Serialize(stream, t);
return stream.ToArray();
}
}
public static T Deserialize<T>(byte[] b) {
IFormatter formatter = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream(b)) {
return (T)formatter.Deserialize(stream);
}
}
------------------------------------------
除非特别声明,文章均为原创,版权与博客园共有,转载请保留出处
BUY ME COFFEE

浙公网安备 33010602011771号