无过载需要“0”参数 [c#]

发布于 2024-11-27 22:17:38 字数 1769 浏览 0 评论 0原文

我在 Start(); 处收到“没有重载需要 0 参数”的错误;我的主要方法中的一行。我不知道如何解决它,我四处寻找但找不到任何东西。

 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")
                {

                    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;
        }


    }
}

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")
                {

                    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;
        }


    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

怪异←思 2024-12-04 22:17:38

对 Start 的方法调用应该是

Start("Something");

Edit: 正如其他人指出的那样:将任何内容传递给 Start() 是没有意义的。传入的移动值将被忽略并替换为从控制台读取的值。因此,我建议简单地从 Start() 方法签名中删除参数,以便它只读取

public static string Start()

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()
赴月观长安 2024-12-04 22:17:38

由于您正在从控制台读取移动,因此从 Start 的参数定义中删除 string move 并将其作为局部变量移动到内部,应该没问题:

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

顺便说一句,您的 main 应该be Main - 在 c# 中,main 应该大写 M!

我建议您阅读一些 C# 基础知识。

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#.

沩ん囻菔务 2024-12-04 22:17:38

提示:这是您的方法调用:

 Start();

这是方法的签名:

 public static string Start(string move)

它们之间不匹配...

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...

┾廆蒐ゝ 2024-12-04 22:17:38

你的 Start(arg) 应该是这样的:

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

Your Start(arg) should be like:

private static string Start()
{
   string move = null;
   ...
}
辞旧 2024-12-04 22:17:38

start 方法需要一个字符串作为参数:

示例:
开始(“r”);
开始(“s”);
开始(“f”);

The start method expects a string as a parameter:

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

债姬 2024-12-04 22:17:38

您应该在调用 Start() 时传递一个参数(如 Anders 建议的那样),或者应该从 Start() 中删除该参数并将其声明为局部变量:

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

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文