Serialization is a process where we can convert an object state in to stream of bytes. This stream can then be persisted in a file,database, or sent over a network etc. Deserialization is just vice-versa of serialization where we convert stream of bytes back to the original object.
Figure 2.6: - serialization and deserialization in .NET
Below is a simple code of how to serialize and de-serialize an object.
Let’s first start with serialization.
Step 1:- Create the object and put some values
Step 2:- Create the file where to save the object.
Step 3:- Use serialize method to save it to hard disk
Let’s also see a simple example of de-serialization.
Step 1:- Read the file
Step 2:- Recreate it back to the original object.
If you want to save to XML or any other content type use the appropriate formatter.
Also see following video on important .NET interview questions on REGEX: -