My task was to serialize and deserialize an object.
I want to know:
- Whether my object is serialized in the way I'm doing it
- How I get to know that my object is being serialized or deserialized
Instead of passing the object in the Serialize Method, I am passing object.properties
. Does this affect it in any way?
FileStream fs = new FileStream(@"D:\Rough Work\Serialization\Serialization\bin\Debug\Log.txt",FileMode.OpenOrCreate);
Laptop obj = new Laptop();
obj.Model = 2;
obj.SerialNumber = 4;
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, obj.Model);
formatter.Serialize(fs, obj.SerialNumber);
[Serializable]
class Laptop
{
public int Model;
public int SerialNumber;
}