close
Constructors 有多型
可用 this 調用另一個構造器,依 Java 的概念,使用 Constructors 時 要多宣告一個無參數引入
避免 出錯
class Employee{
public int Id{get;,set;};
public string FirstName{get;,set;};
public string LastNmae{get;,set;};
public Employee(){} <--避免使用者使用錯誤
public Employee(string firstName,string lastName){
FirstName = firstName;
LastName = lastName;
}
public Empolyee(int id , string firstName, string lastName){
Id = id;
this(firstName,lastName); <---用this 調用
}
}
全站熱搜