示例#1
0
        public static void Main(string[] args)
        {
            // Person1
            Person1 p1 = new Person1("Jack", 28);

            p1.name = "Jill";
            Console.WriteLine(p1.age);

            // Person2
            Person2 p2 = new Person2("Jack", 28);

            p2.SetName("Jill");
            Console.WriteLine(p2.GetAge());

            // Person3
            Person3 p3 = new Person3("Jack", 28);

            p3.Name = "Jill";
            Console.WriteLine(p3.Age);

            Person4 p4 = new Person4("Jack", 28);

            //p4.Name = "Jill";
            Console.WriteLine(p4.Age);

            // Person5
            Person5 p5 = new Person5("Jack", 30);

            p5.Age = -5;
            Console.WriteLine(p5.Age);
        }
示例#2
0
        public static void Main(string[] args)
        {
            // Person1
            Person1 p1 = new Person1("Jack", 28);
            p1.name = "Jill";
            Console.WriteLine(p1.age);

            // Person2
            Person2 p2 = new Person2("Jack", 28);
            p2.SetName("Jill");
            Console.WriteLine(p2.GetAge());

            // Person3
            Person3 p3 = new Person3("Jack", 28);
            p3.Name = "Jill";
            Console.WriteLine(p3.Age);

            Person4 p4 = new Person4("Jack", 28);
            //p4.Name = "Jill";
            Console.WriteLine(p4.Age);

            // Person5
            Person5 p5 = new Person5("Jack", 30);
            p5.Age = -5;
            Console.WriteLine(p5.Age);
        }