Exemple #1
0
        private void TestBinaryFormatter()
        {
            Student std = new Student() { Name = "Mark", Age = 20 };
            Teacher ter = new Teacher() { Name = "Jim", Age = 21 };

            using (FileStream  fs =new FileStream(@"Student.dat", FileMode.Create))
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs,std);
                bf.Serialize(fs,ter);
            }
        }
Exemple #2
0
 private void TestXmlSerializer()
 {
     Student std = new Student() { Name="Mark",Age=20};
     XmlSerializer xs = new XmlSerializer(typeof(Student));
     using (Stream stream = new FileStream(@"Student.xml", FileMode.Create, FileAccess.Write, FileShare.Read))
     {
         xs.Serialize(stream, std);
     }
 }