. NET serialization and deserialization

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.