构造函数的执行顺序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BCode_Framework_ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer customer = new Customer("aa", "bb");
            Console.WriteLine(customer.aa);
            Console.WriteLine(customer.bb);
            Console.WriteLine(customer.ee);
            Console.ReadLine();

        }
    }
    public class Customer
    {
        public string aa = "aa未初始化";
        public string bb = "bb未初始化";
        public string ee = "ee未初始化";
        public int i = 0;

        public Customer()
        {
            this.aa = i.ToString();
            i++;
        }
        public Customer(string aa):this()
        {
            this.bb = i.ToString();
            i++;
        }
        public Customer(string aa,string bb):this(bb)
        {
            this.ee = i.ToString();
            i++;
        }

    }
}

猜你喜欢

转载自www.cnblogs.com/heibai-ma/p/11276972.html