/// <summary> /// method for serialization /// </summary> public void Slz() { log4net.ILog log = log4net.LogManager.GetLogger(typeof(Serialz)); try { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("e:\\F1.txt", FileMode.OpenOrCreate); Stud s = new Stud(2, "abc"); formatter.Serialize(stream, s); stream.Close(); log.Info("serialization done"); } catch (SerializationException se) { log.Info("Failed to serialize. Reason: " + se.Message); } }
/// <summary> /// method for deserialization /// </summary> public void Dslz() { log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program)); try { FileStream stream = new FileStream("e:\\F1.txt", FileMode.OpenOrCreate); BinaryFormatter formatter = new BinaryFormatter(); Stud s = (Stud)formatter.Deserialize(stream); log.Info("value after deserialization"); log.Info("Rollno: " + s.roll); log.Info("Name: " + s.name); stream.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }