【问题标题】:No overload for method 'run' takes 1 arguments方法'run'没有重载需要1个参数
【发布时间】:2015-09-22 00:08:04
【问题描述】:

当我遇到这个小问题时,我正在 COSMOS 中创建一个操作系统。

else if (HOLOOS.seperate(MyGlobals.input, 5) == "login")
{
    if (MyGlobals.input == "login")
    {
        Console.Write(Commands.login.usage);
    }
    else
    {
        var arg = HOLOOS.rseperate(MyGlobals.input, 6, (MyGlobals.input.Length - 1));
        arg = HOLOOS.GatherArgs(arg);
        login.run(arg);
    }
}

这是登录类..我猜公共静态无效运行有什么问题?

class login
{
    public static string CurrentUser;
    public static void run(string EnteredUser, string EnteredPassword, string User1CorrectName, string User1CorrectCode, string User2CorrectName = "", string User2CorrectCode = "")
    {
        string EnteredHashedPassword = BashUtils.Encrypt(EnteredPassword);
        //Check if the user name is 
        if (EnteredUser == User1CorrectName)
        {
            //If the user name entered is jacob, then check if the password is OK
            if (EnteredHashedPassword == BashUtils.Encrypt(User1CorrectCode))
            {
                //If password is okay than login
                Console.Write("You have sucessfully logged in as " + User1CorrectName);
                CurrentUser = User1CorrectName;
                cd.Path = "D:\\" + User1CorrectName + "\\";
            }
            //If the password is not OK then say so
            else
            {
                Console.Write("Not correct password for " + User2CorrectName);
            }

        }

【问题讨论】:

  • 你的 run 方法有 4 个非可选参数,而你的调用只有一个 (arg)

标签: c# system overloading dos cosmos


【解决方案1】:

您在这一行中传递了一个参数:

login.run(arg);

到方法run()

当方法的签名是这样的:

public static void run(string EnteredUser, string EnteredPassword, string User1CorrectName, string User1CorrectCode, string User2CorrectName = "", string User2CorrectCode = "")

如您所见,前 4 个参数是必填,因此您应该将它们传递给函数。或修改运行的签名。

最后 2 个参数有一个默认值,即空字符串“”。因此,如果您不需要这些值,则无法传递它们(如果您不将其作为参数传递,则会为其分配默认值)。

阅读此文档以获取参数和默认值MSDN,以获取包含许多示例的完整说明。

在这种情况下,我肯定会使用命名参数,但这只是一种意见。阅读文档,如果您有不明白的地方,请询问。

【讨论】:

    猜你喜欢
    • 2013-04-23
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多