當我嘗試運行我的代碼時,我收到錯誤消息'沒有超載的方法'說話'需要0個參數',有人可以幫我調用talk()方法。對不起,代碼很長,但我真的不明白,我錯了。無法從類內調用方法?
class Program
{
public void Main(string[] args)
{
Critter newcritter = new Critter();
Console.WriteLine("Enter critter name: ");
var newname = Convert.ToString(Console.ReadLine());
newcritter.Name = newname;
Console.WriteLine("Say Hello to your new critter, {0}!", newcritter.Name);
var option = Convert.ToString(Console.ReadLine());
while (option != "0")
{
Console.WriteLine(@"
Critter Caretaker
0 - Quit
1 - Listen to your critter
2 - Feed your critter
3 - Play with your critter
");
if (option == "0")
{
Console.WriteLine("Good-bye.");
}
if (option == "1")
{
newcritter.talk();
}
class Critter
{
public string Name { get; set; }
public int Hunger = 0;
public int Boredom = 0;
public void PassTime()
{
Hunger += 1;
Boredom += 1;
}
public void mood()
{
var unhappiness = Hunger + Boredom;
string m = "";
if (unhappiness < 5)
{
m = "Happy";
}
if (unhappiness <= 5 &&
unhappiness <= 10)
{
m = "Okay";
}
if (unhappiness <= 11 &&
unhappiness <= 15)
{
m = "Frustrated";
}
if (unhappiness <= 16)
{
m = "Mad";
}
}
public void talk(string m)
{
Console.WriteLine("I'm", Name, "and I feel", m, "now.\n");
PassTime();
}