开发者

No overload takes '0' arguments [c#]

I am getting an error of "No overload takes 0 args" at the Start(); line in my main method. I do not know how to fix it, and I've searched around and couldn't find anything.

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication1
    {
        class Program
        {
            public static void main(string[] args)
            {
                Start();
            }

            public static string Start(string move)
            {



                Console.Write("");
                string gameType = Console.ReadLine();

                if (gameType == "s")
                {

     开发者_StackOverflow社区               Console.Write("");
                begin:
                    Console.Write("\nEnter your move: ");
                    move = Console.ReadLine();


                    switch (move)
                    {
                        case "r":
                            Console.Write("s");
                            Console.ReadLine();

                            break;
                        case "s":
                            Console.Write("");
                            Console.ReadLine();

                            break;
                        case "f":
                            Console.Write("");
                            Console.ReadLine();

                            break;
                        default:
                            Console.Write("\nInvalid move, try again\n\n");


   goto begin;
                }
                Console.ReadLine();
                return move;
            }
            else
            {
                return move;
            }
        }


        static string Genius(string genius, string move)
        {
            Console.Write(move);
            return genius;
        }


    }
}


The method call to Start should should be

Start("Something");

Edit: as others have pointed out: there is no point in passing anything to Start(). The move value passed in is ignored and replaced by whatever is read from the console. Therefore I suggest simply removing the argument from the Start() method signature so it just reads

public static string Start()


Since you are reading the move from the console, remove the string move from the parameter definition of Start and move it inside as a local variable and it should be fine:

public static string Start()
        { string move;
          ...

And btw, your main should be Main - in c# the main should have a capital M!

I recommend you read some basics of C#.


Hint: this is your method call:

 Start();

and this is the method's signature:

 public static string Start(string move)

There is a mismatch between them...


Your Start(arg) should be like:

private static string Start()
{
   string move = null;
   ...
}


The start method expects a string as a parameter:

Examples:
Start("r");
Start("s");
Start("f");


You should either pass an argument when Start() is called (as Anders suggested) or you should remove the argument from Start() and declare it as a local variable instead:

    public static string Start()
    {
        string move = string.Empty;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜