static void DeserializeIt() { //de-serialization Stream stream = File.Open(fpath, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); Usr obj = (Usr)bf.Deserialize(stream); stream.Close(); Console.WriteLine("... Deserialization"); Console.WriteLine("After: " + obj); }
static void SerializeIt() { Usr obj = new Usr(10, "John"); Console.WriteLine("Before: " + obj); if (File.Exists(fpath)) { File.Delete(fpath); } //serialization Stream stream = File.Open(fpath, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(stream, obj); stream.Close(); Console.WriteLine("Serialization Successful ...."); }