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 調用

   }

 

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Rh 的頭像
    Rh

    程式狂想曲

    Rh 發表在 痞客邦 留言(0) 人氣()