我大量使用字节数组来传输对象,原始数据,通过网络和返回.我通过一个类型实现ISerializable来适应java的方法,它包含两个方法,作为接口的一部分,ReadObjectData和WriteObjectData.使用此接口的任何类都会将日期写入字节数组.像那样的东西
class SerializationType:ISerializable
{
void ReadObjectData (/*Type that manages the write/reads into the byte array*/){}
void WriteObjectData(/*Type that manages the write/reads into the byte array*/){}
}
Run Code Online (Sandbox Code Playgroud)
写完所有对象后,我发送一个网络数组.
这实际上是双重问题.这是通过网络以最高效率(速度,大小)发送数据的正确方法吗?
您是否会使用此方法将对象写入文件,而不是通常使用xml序列化?
编辑#1
Joel Coehoorn提到了BinaryFormatter.我从未使用过这门课.除了我目前在msdn上看到的内容之外,你会详细说明,提供好的例子,参考资料,建议,当前的做法吗?