Search code examples
c#systemoverloadingdoscosmos

No overload for method 'run' takes 1 arguments


I'm creating an operating system in COSMOS when I was running into this little problem.

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

This is the login class.. I guess something is wrong with the public static void run?

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

        }

Solution

  • You are passing one argument in this line:

    login.run(arg);
    

    to the method run()

    when the signature of the method is this:

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

    As you can see, the first 4 parameters are mandatory, so you should pass them to the function. Or modified run's signature.

    The last 2 parameters have a default value, the empty string "". So, you could not pass those values if you don't need them (this will be assigned with the default value if you don't pass it as an argument).

    Read this documentation for parameters and default values MSDN for a complete description with many examples.

    I would definitely go with named parameters in that case, but this is just an opinion. Read the docs, if you don't understand something just ask.