Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //personinfo pi = new personinfo("clark", 53);
            //SearialiseData sd = new SearialiseData();
            //sd.SaveData(pi);

            SearialiseData sd = new SearialiseData();
            personinfo     pi = new personinfo();

            pi.showdata();
            pi = sd.Getdata();
            pi.showdata();
        }
Exemplo n.º 2
0
 public void SaveData(personinfo pi)
 {
     try
     {
         file = new FileStream("c:\\Files\\Personinfo.bin", FileMode.Create, FileAccess.Write);
         BinaryFormatter format = new BinaryFormatter();
         format.Serialize(file, pi);
         Console.WriteLine("data serializes");
     }
     catch (IOException ex)
     {
         Console.WriteLine(ex.Message);
     }
     finally
     {
         file.Close();
     }
 }
Exemplo n.º 3
0
        public personinfo Getdata()
        {
            personinfo ps = null;

            try
            {
                file = new FileStream("c:\\Files\\Personinfo.bin", FileMode.Open, FileAccess.Read);
                BinaryFormatter format = new BinaryFormatter();
                ps = (personinfo)format.Deserialize(file);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                file.Close();
            }
            return(ps);
        }