我在Start()时收到“No overload take 0 args”错误;在我的主要方法中。我不知道如何解决它,我已经四处搜索,找不到任何东西。
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;
}
}
}
答案 0 :(得分:8)
对Start的方法调用应该是
Start("Something");
编辑:正如其他人所指出的那样:向Start()传递任何东西都没有意义。传入的移动值将被忽略,并替换为从控制台读取的任何内容。因此,我建议简单地从Start()方法签名中删除该参数,以便它只读取
public static string Start()
答案 1 :(得分:2)
由于您正在从控制台读取移动,因此从Start的参数定义中删除string move
并将其作为局部变量移入其中,它应该没问题:
public static string Start()
{ string move;
...
顺便说一句,你的主要应该是主 - 在c#中主要应该有一个大写字母M!
我建议你阅读一些C#的基础知识。
答案 2 :(得分:1)
提示:这是你的方法调用:
Start();
这是该方法的签名:
public static string Start(string move)
他们之间存在不匹配......
答案 3 :(得分:0)
你的开始(arg)应该是:
private static string Start()
{
string move = null;
...
}
答案 4 :(得分:0)
start方法需要一个字符串作为参数:
示例:
启动( “R”);
启动( “S”);
启动( “F”);
答案 5 :(得分:0)
你应该在调用Start()时传递一个参数(如Anders建议的那样),或者你应该从Start()中删除参数并将其声明为局部变量:
public static string Start()
{
string move = string.Empty;