Пример #1
0
        static void Main(string[] args)
        {
            //personinfo pi = new personinfo("martin", 22);
            searialise s = new searialise();
            // s.savedata(pi);
            personinfo pnew = new personinfo();

            pnew.showdata();
            pnew = s.getdata();
            pnew.showdata();
        }
Пример #2
0
 public void savedata(personinfo pi)
 {
     try
     {
         fs = new FileStream(@"c:\Files\personinfo.xml", FileMode.Create, FileAccess.Write);
         XmlSerializer xs = new XmlSerializer(typeof(personinfo));
         xs.Serialize(fs, pi);
         Console.WriteLine("data serialized");
     }
     catch (IOException ex)
     {
         Console.WriteLine(ex.Message);
     }
     finally
     {
         fs.Close();
     }
 }
Пример #3
0
        public personinfo getdata()
        {
            personinfo pi = null;

            try
            {
                fs = new FileStream(@"c:\Files\personinfo.xml", FileMode.Open, FileAccess.Read);
                XmlSerializer xs = new XmlSerializer(typeof(personinfo));
                pi = (personinfo)xs.Deserialize(fs);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                fs.Close();
            }
            return(pi);
        }