Home >Backend Development >C#.Net Tutorial >Serialization and Deserialization in C#
Serialization converts an object into a stream of bytes and converts it into a form that can be written to the stream. This is done to save it to memory, file or database.
The following serialization operations can be performed:
All members, even read-only members, will be serialized.
It serializes the public fields and properties of an object into an XML stream that conforms to a specific XML schema definition language document.
Let's look at an example. First set up the stream:
FileStream fstream = new FileStream("d:\ew.txt", FileMode.OpenOrCreate); BinaryFormatter formatter=new BinaryFormatter();
Now create an object of this class and call the constructor with three parameters -
Employee emp = new Employee(030, "Tom", “Operations”);
Perform the serialization.
formatter.Serialize(fStream, emp);
Deserialization is the reverse process of serialization, through which you can read objects from a byte stream.
formatter.Deserialize(fStream);
The above is the detailed content of Serialization and Deserialization in C#. For more information, please follow other related articles on the PHP Chinese website!