我沒有使用C#的經驗,但作爲我們大學模塊之一,我們必須創建一個老虎機應用程序。我們創建了一個賭徒類,我必須創建一個CheckBalance類,我將從Gambler類中調用Token方法。但是我收到了在主題標題中提到的錯誤。非靜態字段方法需要對象方法
Int tokens = Gambler.Tokens;
上述行是我得到我的錯誤。 這是我的代碼:
enter code herenamespace CasinoClasslibrary
{
public class Gambler
{
public string Name { get; private set; }
public int Age { get; private set; }
public long CreditCardNum { get; private set; }
public int Tokens { get; public set; }
public string Username { get; private set; }
public string Password { private get; public set; }
public Gambler(string Name, int Age, long CreditCardNum, int Tokens, string Username, string Password)
{
this.Name = Name;
this.Age = Age;
this.CreditCardNum = CreditCardNum;
this.Tokens = Tokens;
this.Username = Username;
this.Password = Password;
}
}
public class Cashout : Gambler
{
public Boolean CheckBalance()
{
int tokens = Gambler.Tokens;
return true;
}
}
}