コード例 #1
0
        public static void SerializePerson2Demo()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            SerializePerson2(@"C:\SerializedPerson2.txt", formatter);

            Person2 person = DeserializePerson2(@"C:\SerializedPerson2.txt", formatter);

            Console.WriteLine(person.ToString());
            Console.ReadLine();
        }
コード例 #2
0
        public static void SerializePerson2(string fileName, IFormatter formatter)
        {
            Person2 person = new Person2();

            person.DateOfBirth = new DateTime(1998, 9, 17, 18, 32, 0);
            person.Name        = "Máté";
            person.Gender      = Gender.Male;
            person.SetAgeManually();

            FileStream stream = new FileStream(fileName, FileMode.Create);

            formatter.Serialize(stream, person);
            stream.Close();
        }