Serialization and deserialization
Serialization is the process of converting an object into a stream of data so that it can be easily transmittable over the network
Serialization
Serialization is the process of converting an object into a stream of data so that it can be easily transmittable over the network
if you want to store an object (or multiple objects) in a file for later retrieval,
you store the output of serialization. The next time you want to read the objects, you
call the deserialization methodsTo serialize an object
* Create an object Stream
* Create a BinaryFormatter
* Call the BinaryFormatter.Serialize method to serialize
string data = "This must be stored in a file or folder";
FileStream fs = new FileStream("Serialization.Data", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, data);
fs.Close();
If you open the file in a notepad you can notice the contents of your file surrounded by binary numbersDeSerialiazation
Deserialization is the process of converting a previously serialized sequence of bytes into an objectTo deserialize
* Create an object Stream to read a serialized output
* Create a BinaryFormatter object
* Create an object to store a Deserialized data
* USE the BinaryFormatter.Deserialize method to deserialize the object
filestream fs = new FileStream("Serialize.Data", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
string data = "";
data = (string)bf.Deserialize(fs);