无过载需要“0”参数 [c#]
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对 Start 的方法调用应该是
Edit: 正如其他人指出的那样:将任何内容传递给 Start() 是没有意义的。传入的移动值将被忽略并替换为从控制台读取的值。因此,我建议简单地从 Start() 方法签名中删除参数,以便它只读取
The method call to Start should should be
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
由于您正在从控制台读取移动,因此从 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: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:
and this is the method's signature:
There is a mismatch between them...
你的 Start(arg) 应该是这样的:
Your Start(arg) should be like:
start 方法需要一个字符串作为参数:
示例:
开始(“r”);
开始(“s”);
开始(“f”);
The start method expects a string as a parameter:
Examples:
Start("r");
Start("s");
Start("f");
您应该在调用 Start() 时传递一个参数(如 Anders 建议的那样),或者应该从 Start() 中删除该参数并将其声明为局部变量:
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: