Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is serialization? and how it can be implemented? can anyone explain it with help of best understandable example?
Posted

serialization is the process of translating an object that is represented in memory, into a "flat" format that can be stored, usually in a text format, or a byte array.

the serialization needs to be two way- to allow a reader to recreate the object from the flat format.

for example:

C#
int number = 5;

string serializedText = SomeSerializationUtility.SerializeToString(number);
int number2 = SomeSerializationUtility.DeserializeFromString(serializedText );

Asset.AreEqual(number, number2);


of course things get a lot more complicated when serializing objects that have multiple properties, and internal states, and perhaps inner properties that are themselves complex types.

so for example:

C#
public class MyData
{
   public string Text;
   public int Number;
   public List<double> data;
}
</double>


could be represented in the following XML format:
XML
<mydata>
   <text type="string">blabla</text>
   <number type="int">5</number>
   <data type="List<double>"><item>0.0</item></data>
</mydata>


and you should be able to easily see how this data is mapped between XML elements and class properties.
 
Share this answer
 
I think that you should try reading something like this[^] on MSDN.
Nice example there.

Happy coding.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900