 Hello everyone and welcome to the session on serialization and deserialization in C-sharp.NET. At the end of this session, student will be able to implement C-sharp.NET programs to perform serialization and deserialization. Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called as deserialization. This diagram shows the overall process of serialization. The object is serialized to a stream that carries the data. The stream may also have information about the object's type such as version, structure, assembly name, etc. From that stream, the object can be stored in a database, a file or memory. The easiest way to make a class serializable is to mark it with serializable attribute. It indicates that a class can be serialized. This class cannot be inherited. Now pause the video and find the answer. Which of the following attributes should we use to make a class serializable? A. i serializable. B. serializable. C. non-serialized. D. on deserialization. The answer is B. serializable. Now let's see a program to perform serialization and deserialization. Here we have used system.io namespace because we want to serialize the object of student class to a file stream and system.runtime.serialization namespace contains the classes for serialization and deserialization. Here we have created a class student with two private fields, roll number and name and this is the constructor of student class. Here I have assigned value 5 to roll number and a string, Anjali is assigned to name. To serialize the object of student class, I have to use serializable attribute for this class. Then after deserialization, I want to display the roll number and name of the object. So I have to use display method. I will define it first. Public void display console.writeLine method and I will display roll number plus space plus name. For serialization, first I have to create the object of student class. So here we will create the student's object, student s equal to new student. Then I will create binary formatter object, binary formatter f equal to new binary formatter. Then I have to serialize the object to a file stream. So I have to create a stream first, stream st equal to new file stream. Then I will specify the path of the file slash a dot bin. Then the next parameter is file mode. File mode will be create mode because we want to create a file and file access will be write access because we want to write to the file. Then here I have created the stream. Now I have to serialize the object to this particular stream. So I have to use binary formatter serialized method. The first parameter is stream and the next parameter is object to be serialized. Now here we have finished serialization. So I will close the stream. I have to create a stream once again for deserialization. So st equal to new file stream. I will specify the same path as we have specified earlier. Then the next parameter is file mode. File mode will be open mode because here we are deserializing, file access. File access will be read access. Then I will create student reference student obj equal to then I have to deserialize the object. So I have to use formatter dot deserialize. Then I have to pass the stream here. But I have to use casting. So I have to specify the student type here. Now we have finished the process of deserialization. So I will close the stream. Then I will call display method on this object so that we will display the roll number and name of the student after deserialization. Then I will use console dot read key method. Let's build the code. Build is successful. The object was serialized to the file stream and it is again deserialized and these are the values 5 and these are the values of private fields of the object and these are displayed after deserialization. Let's see the file where it is stored. This is a dot bin. Here you can see the other information such as version, culture, etc and these are the private fields of the attribute roll number name and the values are also stored. In this session we have seen the concept of serialization and deserialization in C sharp dot net. Thank you.