..
In certain circumstances, applications may have the need to store or transfer data contained in certain objects, to make these operations the simplest possible. NET Framework provides several techniques for serialization. These techniques allow you to convert objects into binary data, SOAP or XML through which to easily manage the storage and transfer of the same.
When you create an object in an application. NET is often not reflected on the ways in which data is stored because the. NET Framework handles this issue automatically. However if you want to store the contents of an object in a file, send an object to another process or transmit through the network you need to know the object is represented, because you will probably need to convert it into a different format. This conversion is called serialization.
Serialization, implemented in the System.Runtime.Serialization namespace, is a process that converts an object into a linear sequence of bytes to be stored or transferred. Deserialization is the opposite process or the conversion of a sequence of bytes in a serialized object.
Let us now see the steps to follow to make the serialization of an object:
string data = "Data to be stored in a file."
/ / Create the file in which to store data
FileStream fs = new FileStream ("C: \ \ Serializzazione.txt", FileMode.Create);
/ / Create a BinaryFormatter object to perform serialization
BinaryFormatter bf = new BinaryFormatter ();
/ / Use the BinaryFormatter object to
/ / Serialize the data and insert them in the file
bf.Serialize (fs, data);
/ / Close the file
fs.Close ();
Launching the application and opening the file with Notepad Serializzazione.txt generated we will see that it contains the string we set in our example, accompanied by binary information (that Notepad will display as symbols) that are useful for subsequent deserialization

| |
Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €. |
| |
SQL and Database (Course)
Create and manage relational databases. From 39 €. |
| |
Webmaster Advanced (Course)
Become a professional Webmaster. From 39 €. |