1. Serialization deserialization
In C # if needed: to store objects of a complex class, or to be transmitted over a network to a remote client program, serialization, deserialization (serialization & deserialization) is required
2.BinaryFormattter
. NET has three kinds of serial, BinaryFormatter, SoapFormatter and XmlSerializer.
Where Binaryformattter is the simplest, it is directly in binary mode to the objects (object) serial or crossdress, his advantage is fast, can be serial private or protected member, in different versions. NET are compatible and can be seen as. NET own life method, of course, the shortcomings will follow, and left. NET it can't live, so it can't be done on other platforms or across networks.
3. Serialization
BinaryFormatter ser = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
Ser. Serialize (MS, DS);
byte[] buffer = Ms. ToArray ();
MemoryStream: Create a stream that supports storage as memory
4. Deserialization
Deserialization: The byte[] type of data is put into the stream, BinaryFormatter the data in the stream is deserialized into an object
MemoryStream ms = new MemoryStream (bytes);
BinaryFormatter ser = new BinaryFormatter ();
DataSetSurrogate DSS = ser. Deserialize (ms) asdatasetsurrogate;
5. Summary
The serialization, deserialization, and use of binaryformate, all have to borrow ordinary flow MemoryStream, the difference is:
When serializing, serializes an object into MemoryStream, and deserializes the byte[] data in MemoryStream into an object when deserialized
- Serializeutil.rar (571 Bytes)
. NET serialization and deserialization