What is serialization?
The runtime environment of ---.net is used to support the streaming mechanism of user-defined types. It stores the status of the object instance to the stored media. In this process, the public and private fields of the object and the name of the class (including
Program Set), and then write the byte stream into the data stream. When the object is deserialized, a copy identical to the original object will be created.
Serialization objective:
1. Make the custom object persistent in a certain storage form;
2. transfer an object from one place to another.
Essentially, the serialization mechanism is to convert the class value into a general (that is, continuous) byte stream, and then the stream can be written to a disk file or any other streaming target. To write this stream, you must use the serialize and deserialize methods in the classes that implement the iformatter interface.
Private bool serializestudent (Object OBJ)
{
Filedialog FD = new savefiledialog ();
If (FD. showdialog () = dialogresult. OK | FD. filename! = NULL)
{
Filestream FS = new filestream (FD. filename, filemode. Create, fileaccess. Write );
System. xml. serialization. xmlserializer xmlser = new system. xml. serialization. xmlserializer (obj. GetType ());
Xmlser. serialize (FS, OBJ );
FS. Close ();
Return true;
}
Else
{
Return false;
}
}
Private object deserializestudent (Object OBJ)
{
Filedialog FD = new openfiledialog ();
Object objstd;
If (FD. filename! = NULL | FD. showdialog () = dialogresult. OK)
{
Filestream FS = new filestream (FD. filename, filemode. Open, fileaccess. Read, fileshare. Read );
System. xml. serialization. xmlserializer xmlser = new system. xml. serialization. xmlserializer (obj. GetType ());
Objstd = xmlser. deserialize (FS );
FS. Close ();
Return objstd;
}
Else
{
Return NULL;
}
}