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

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)");
        }
    }

  输出结果:

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

 

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案