Difference between BinaryWriter and BinaryFormatter.Serialize?
BinaryWriter
is used to write primitive types in binary to a stream and supports writing strings in a specific encoding. BinaryFromatter
is responsible for serializing an entire object or graph of connected objects into binary format. So, I suppose you can say BinaryWriter
is a much more elementary form of something like BinaryFormatter
.
I got this information here: BinaryWriter & BinaryFormatter
BinaryWriter
and BinaryFormatter
are two different thing.
BinaryFormatter
is used for serialization. It helps you to map a C# object to a binary representation which you can write to a file, a network stream etc.
But BinaryWriter
does not help you map the C# object to binary data. It just gives you the ability to write binary data (as the name implies). So you give it primitive types like an int, it converts it into binary and write it. After writing when you need reading it you have to use a BinaryReader
and you must know somehow that you have to read an int. So you have to serialize your data somehow yourself.
You can say BinaryFormatter
uses BinaryWriter
to be able to write binary data but it does a lot of other jobs to automatically serialize and deserialize your object.