Esempio n. 1
0
 public static void BinarySerialize(UserInfo user)
 {
     FileStream fs = new FileStream("MySerialze.bin", FileMode.Create);
     BinaryFormatter formatter = new BinaryFormatter();
     //ִ�ж��������л�
     formatter.Serialize(fs, user);
     fs.Close();
 }
Esempio n. 2
0
 //Main_9_4_7
 public static void Main_9_4_7()
 {
     UserInfo user = new UserInfo("��", 26, true);
     //ִ�����л�
     BinarySerialize(user);
     //ִ�з����л�
     UserInfo user2 = BinaryDeserialize();
     Console.WriteLine("Name:{0}\nAge:{1}\nVip:{2}", user2.Name, user2.Age, user2.IsVIP);
 }
Esempio n. 3
0
        //Main_9_4_8
        public static void Main_9_4_8()
        {
            UserInfo user = new UserInfo("��", 27, false);
            XmlSerializer serialsizer = new XmlSerializer(typeof(UserInfo));

            //ִ�����л�����
            StreamWriter sw = new StreamWriter("MySerialze.xml");
            serialsizer.Serialize(sw, user);
            sw.Close();

            //ִ�з����л�����
            FileStream fs = new FileStream("MySerialze.xml", FileMode.Open);
            UserInfo user2 = serialsizer.Deserialize(fs) as UserInfo;

            Console.WriteLine("Name:{0}\nAge:{1}\nVip:{2}\nDes:{3}", user2.Name, user2.Age, user2.IsVIP, user2.ShowDes());
        }