예제 #1
0
        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);
        }
예제 #2
0
        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 ....");
        }