static void Main(string[] args)
        {
            FileStream      stream    = new FileStream("g:\\UUU.txt", FileMode.OpenOrCreate); // writing single byte into file using open or create mode for read and write
            BinaryFormatter formatter = new BinaryFormatter();                                //BinaryFormatter is used to serialize an object (meaning it converts it to one long stream of 1s and 0s)

            Student1 s = new Student1(1001, "krishna");

            formatter.Serialize(stream, s);

            stream.Close();

            Console.WriteLine("Done");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            FileStream      stream    = new FileStream("g:\\UUU.txt", FileMode.Open);
            BinaryFormatter formatter = new BinaryFormatter();


            Student1 s1 = (Student1)formatter.Deserialize(stream);// method to deserialize to stream

            Console.WriteLine("Rollno:" + s1.rollno);
            Console.WriteLine("Name:" + s1.name);

            stream.Close();
            Console.ReadLine();
        }