예제 #1
0
파일: MainApp.cs 프로젝트: agahong/C_Sharp
        static void Main(string[] args)
        {
            Stream          ws         = new FileStream("a.dat", FileMode.Create);
            BinaryFormatter serializer = new BinaryFormatter();

            NameCard nc = new NameCard();

            nc.Name  = "박상현";
            nc.Phone = "010-123-4567";
            nc.Age   = 33;

            serializer.Serialize(ws, nc);
            ws.Close();

            Stream          rs           = new FileStream("a.dat", FileMode.Open);
            BinaryFormatter deserializer = new BinaryFormatter();

            NameCard nc2;

            nc2 = (NameCard)deserializer.Deserialize(rs);
            rs.Close();

            Console.WriteLine("Name:  {0}", nc2.Name);
            Console.WriteLine("Phone: {0}", nc2.Phone);
            Console.WriteLine("Age:   {0}", nc2.Age);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Stream          ws         = new FileStream("a.dat", FileMode.Create);
            BinaryFormatter serializer = new BinaryFormatter();

            NameCard nc = new NameCard();

            nc.Name  = "pi";
            nc.Phone = "000-0000";
            nc.Age   = 6;

            serializer.Serialize(ws, nc);
            ws.Close();

            Stream          rs           = new FileStream("a.dat", FileMode.Open);
            BinaryFormatter deserializer = new BinaryFormatter();

            NameCard nc2;

            nc2 = (NameCard)deserializer.Deserialize(rs);
            rs.Close();

            Console.WriteLine($"Name:  {nc2.Name}");
            Console.WriteLine($"Phone: {nc2.Phone}");
            Console.WriteLine($"Age:   {nc2.Age}");
        }