예제 #1
0
파일: Stream.cs 프로젝트: imnhk/CSharpStudy
        static void Serialization()
        {
            FileStream      ws         = new FileStream("s.dat", FileMode.Create);
            BinaryFormatter serializer = new BinaryFormatter();

            NameCard nc = new NameCard();

            nc.name  = "kname";
            nc.phone = "000-000-0001";
            nc.age   = 111;

            serializer.Serialize(ws, nc);

            ws.Close();

            FileStream      rs           = new FileStream("s.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)
        {
            BirthdayInfo birthday = new BirthdayInfo()
            {
                Name     = "myname",
                BirthDay = new DateTime(1892, 3, 23)
            };

            var anonBirthday = new { Name = "anon", Age = 99 };

            Console.WriteLine("Name: {0}", anonBirthday.Name);
            Console.WriteLine("Birthday: {0}", birthday.BirthDay);
            Console.WriteLine("Age: {0}", birthday.Age);

            // EX9_1
            NameCard myCard = new NameCard();

            myCard.Name = "Who";
            myCard.Age  = 222;

            Console.WriteLine("Name: {0}", myCard.Name);
            Console.WriteLine("Age: {0}", myCard.Age);

            // EX9_2
            var otherCard = new { Name = "Somebody", Age = 1000 };

            Console.WriteLine("Name: {0}, Age: {1}", otherCard.Name, otherCard.Age);

            var complex = new { Real = 3, Imaginary = -12 };

            Console.WriteLine("Real: {0}, Imaginary: {1}", complex.Real, complex.Imaginary);
        }