Object Serialization in C#
Object Serialization
* How to serialize/deserialize objects to/from disk files.
How to store the data in a binary file using Object Serialization. Will anybody help me regarding this. i need this urgently.
Will anybody please send the example of this.
thank you.
# 1 Re: Object Serialization in C#
There is a class called BinaryFormatter which will help you to do the work. Have a look at the related MSDN help topic and you will see how to use the class.
torrud at 2007-11-9 11:36:47 >

# 2 Re: Object Serialization in C#
This Sudoko Game is an easy example how to store and load a class using binary reader
For testing it fill numbers into the grid and use Save in the menue. Using load you can reload this data. Its easy to understand as I created an extra class in this game only for this purpose. If you have questions feel free to ask
# 3 Re: Object Serialization in C#
This should do it:
private static void Serialize(Person sp)
{
// Create file to save the data to
FileStream fs = new FileStream("Person.Dat", FileMode.Create);
// Create a BinaryFormatter object to perform the serialization
BinaryFormatter bf = new BinaryFormatter();
// Use the BinaryFormatter object to serialize the data to the file
bf.Serialize(fs, sp);
// Close the file
fs.Close();
}
# 4 Re: Object Serialization in C#
If you want to serialize a class as it is you can simple use ntfishersdk example. If you need to serialize spezific values of a class controling which item to serialitze and which you didn't want to serialize then you can do serialisation totally controled by your code as I did in my example. This depends on what you need.