我無法讓主讀取我的構造函數。它一直說我的類不包含帶有3個參數的構造函數。它是公開的。我不知道自己做錯了什麼,我在成功之前完成了這個,這是我用來爲我的測試學習的一個練習題。不包含一個構造函數,它接受3個參數
public class Actor
{
//attributes
private string name;
private int awardsNum;
private bool SAGMember;
//property
private string name
{
get { return name; }
set { name = value; }
}
//constructor
public Actor(string Name, int AwardsNum, bool SAGMember)
{
this.name = Name;
this.awardsNum = AwardsNum ++;
this.SAGMember = false;
}
public Actor()
{
this.name = "Bob Smith";
this.awardsNum = 0 ;
this.SAGMember = false;
}
public override string ToString()
{
return string.Format ("Actor: " + name + "\n" + " Number of Awards: " + awardsNum + "\n"+ "SAG Member: " + SAGMember);
}
}
public static void Main (string[] args)
{
Actor a1 = new Actor ("Dustin Hoffman", 0 , true);
Console.WriteLine (a1);
Actor a2 = new Actor();
Console.WriteLine (a2);
}
此外,在構造函數的參數SAGMEMBER是一樣的局部場SAGMEMBER –
沒有'SAGMEMBER'財產演員類,但有一個'SAGMember'屬性。 – Andrew
@安德魯,那是剛剛改變。 –