如何通过BinaryWriter传递,编码和解码对象

时间:2013-03-05 11:11:58

标签: c# streaming

假设我有一个对象Student s = new Student();

此外我有BinaryWriter bw。

如何编码和解码(在BinaryReader上)没有基本类型?

1 个答案:

答案 0 :(得分:0)

使用Binary Serialization

IFormatter formatter = new BinaryFormatter();
formatter.Serialize(bw.BaseStream, s);

确保您的Student类型标记为[Serializable]