c#中 这种构造方法Recer(…):this(…){ }

指的是构造函数首先调用另外一个构造函数

 

class Program
    {
        static void Main(string[] args)
        {
            Person p2 = new Person("Carll",10);

            Console.ReadKey();
        }
    }

    class Person
    {
        public Person()
        {
            Console.WriteLine("P()");
        }

        public Person(string name)
            : this()
        {
            Console.WriteLine("P(name)");
        }

        public Person(string name, int age)
            : this(name)
        {
            Console.WriteLine("P(name, age)");
        }
    }

  输出结果:

  

 

  

posted @ 2017-01-10 08:48  jamess  阅读(262)  评论(0编辑  收藏  举报