我惊讶地发现,无论我在派生类中调用任何构造函数,都调用了我的基类的无参数构造函数.我认为这是什么:base()是为了明确地调用基础构造函数,如果和当我想要的.
using System; namespace TestConstru22323 { class Program { static void Main(string[] args) { Customer customer = new Customer("Jim","Smith"); Customer c = new Customer(); Console.WriteLine(customer.Display()); Console.ReadLine(); } } public class Person { public Person() { Console.WriteLine("I don't always want this constructor to be called. I want to call it explicitly."); } } public class Customer : Person { private string _firstName; private string _lastName; //public Customer(string firstName,string lastName): base() //this explicitly calls base empty constructor public Customer(string firstName,string lastName) //but this calls it anyway,why? { _firstName = firstName; _lastName = lastName; } public string Display() { return String.Format("{0},{1}",_lastName,_firstName); } } }