0

Consider the following:

public void doCommand(string cmd)
  {
    if (cmd == "1"){ tellTime(); }
    else if (cmd == "2"){ getJoke(); }
    else if (cmd == "3"){ playMusic(); }
    else { Console.WriteLine("Say it again"); }
  }
  
public static void Main(string[] args) 
{
  while (true)
  {
      Console.WriteLine("1, 2, or 3?");
      string input = Console.ReadLine();
      doCommand(input);
  }
}

It is giving me this error for some reason:

/home/runner/Nani/main.cs(48,7): error CS0120: An object reference is required for the non-static field, method, or property 'Program.doCommand(string)' [/home/runner/Nani/main.csproj]

The build failed. Fix the build errors and run again.

I have tried to fix it by doing public string doCommand, public static doCommand.

Can anyone please explain what is going wrong here?

0 Answers0