C#-serialization and deserialization

concept

Serialization

By using different classes (BinaryFormatter, SoapFormatter, XmlSerializer) to convert the state of an object into a format that can be retained or transmitted. Specifically, the object is converted into a byte stream. The purpose is to save the state of the data and facilitate subsequent restoration calls. Includes three serialization forms: binary serialization, SOAP serialization, and XML serialization. In contrast to this process, the process of converting a serialized file into an object is called deserialization.

the difference

  1. Binary and SOAP formats can serialize all serializable fields, including public and private fields. The XML format can serialize public fields or private fields with public attributes.
  2. SoapFormatter and BinaryFormatter support remote procedure calls and can serialize graphics.

effect

1. Read the last serialized information when the program starts, which is often used for storage and socket transmission.
2. Transfer data between different processes, for example, you can transfer data between the Web, cross-domain transfer, ASP.NET background code transfers data to the front end.

Binary serialization

First borrow a demo:

using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

namespace 序列化
{
    [Serializable]
    public class SerializeObject
    {
        public int ID
        {
            get;
            set;
        }

  

Guess you like

Origin blog.csdn.net/baidu_35536188/article/details/113927929
Recommended