序列化与反序列化,
流可以是由byte[]实化的MemoryStream
[/Quote]
感谢指教,目前就是用这种方法,代码如下:
//序列化
public static byte[] ObjectToBytes(object obj)
{
using (MemoryStream ms = new MemoryStream())
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
return ms.GetBuffer();
}
}
//反序列化
public static object BytesToObject(byte[] Bytes)
{
using (MemoryStream ms = new MemoryStream(Bytes))
{
IFormatter formatter = new BinaryFormatter();
return formatter.Deserialize(ms);
}
}
[Quote=引用 4 楼 yang_jnu 的回复:]
A a = new A();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, a);
弱弱地问下,fs是一个流对象,怎么获取socket的流?
[/Quote]