Take the 2-minute tour ×

I need to save an object, its serializable but I donot want to use XML. Is it possible to write the raw bytes of the object and then read it off the disk to create the object again?

Thanks for the help!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Yes, it is called binary serialization. There are some good examples on the MSDN site:


share|improve this answer
add comment

Use a BinaryFormatter:

var formatter = new BinaryFormatter();

// Serialize
using (var stream = File.OpenWrite(path))
    formatter.Serialize(stream, yourObject);


// Deserialize
using (var stream = File.OpenRead(path))
    YourType yourObject = (YourType)formatter.Deserialize(stream);
share|improve this answer
add comment

Your Answer

