没有重载方法需要0参数 [英] No Overload for method takes 0 argument

查看:118
本文介绍了没有重载方法需要0参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有以下代码:



 命名空间 timeRecord 
{
public partial class WebLogin:System.Web.UI.Page
{

登录loginclass = 登录();

public void Page_Load(对象发​​件人,EventArgs e)
{


}
public string UserID
{
get { return txtLogUID.Text; }
set {txtLogUID.Text = value ; }
}

public string UserPW
{
get { return txtLogPW.Text; }
set {txtLogPW.Text = value ; }
}
public string UserLevel
{
get { return dropUserLVL.SelectedValue; }
set {dropUserLVL.SelectedValue = value ; }
}

protected void btnLog_Click( object sender,EventArgs e)
{
loginclass.AccountLogin();
}
}
}





和一个等级:



 命名空间 timeRecord 
{
public class 登录
{
DBModule DatabaseModule = new DBModule ();

public string LogMeIn;

public string AccountLogin(WebLogin weblogin)
{

string userID = weblogin.UserID.ToString();
string userPW = weblogin.UserPW.ToString();
string userLevel = weblogin.UserLevel.ToString();

if (userID ==
{
userPW = 哈哈 ;
}

return LogMeIn;
}
}
}





我是面向对象编程的新手,

 loginclass.AccountLogin(); 





一直给我一个错误

方法'AccountLogin'没有超载需要0个参数

如何解决这个问题

解决方案

什么,有可能不清楚?这甚至与OOP无关。您的方法 Login.AccountLogin(WebLogin)需要一个类型 WebLogin 的参数。没有一个具有相同名称的无参数方法, Login.AccountLogin() 。不过,您正在尝试调用 AccountLogin(),即一些不存在的方法,而不解释任何原因。 你正在尝试,没有其他人。你问的是如何解决这个问题。没有什么可以解决的。你需要写下你想要写的东西,而不是随意的东西。



只是旁注:类型字段的惊人名称登录 loginClass 。当人们使用class这个词来命名某个类,或者在可执行文件的名称中使用application,但是在类的实例的名称中使用类时,我看到了这种愚蠢的情况......您需要了解名称应该是合理的,表达它们用于什么的语义,使用正确拼写的英语单词。这很重要,因为,否则,当您在几个月或一年后阅读自己的代码时,您将无法理解它。



-SA


试试这个





 < span class =code-keyword> protected   void  btnLog_Click( object  sender,EventArgs e )
{
WebLogin weblogin = new WebLogin();
weblogin.UserID = UserID;
weblogin.UserPW = UserPW;
weblogin.UserLevel = UserLevel;
loginclass.AccountLogin(weblogin);
}


错误本身就是不言自明的,

没有过载方法'AccountLogin'需要0个参数



您的方法将 WebLogin 作为参数(参数)到函数。

  protected   void  btnLog_Click( object  sender,EventArgs e)
{
WebLogin wl = new WebLogin()
wl.UserID = UserID;
wlUserPW = userPW
loginclass.AccountLogin(wl);
}



未在IDE上测试,但应该可以使用;)



-KR


Hi I have the following code:

namespace timeRecord
{
    public partial class WebLogin : System.Web.UI.Page
    {

        Login loginclass = new Login();

        public void Page_Load(object sender, EventArgs e)
        {
            

        }
        public string UserID
        {
            get { return txtLogUID.Text; }
            set { txtLogUID.Text = value; }
        }

        public string UserPW
        {
            get {return txtLogPW.Text; }
            set { txtLogPW.Text = value; }
        }
        public string UserLevel
        {
            get { return dropUserLVL.SelectedValue; }
            set { dropUserLVL.SelectedValue = value; }
        }

        protected void btnLog_Click(object sender, EventArgs e)
        {
            loginclass.AccountLogin();
        }
    }
}



and a class:

namespace timeRecord
{
    public class Login
    {
        DBModule DatabaseModule = new DBModule();

        public string LogMeIn;

        public string AccountLogin(WebLogin weblogin)
        {

            string userID = weblogin.UserID.ToString();
            string userPW = weblogin.UserPW.ToString();
            string userLevel = weblogin.UserLevel.ToString();

            if (userID == "")
            {
                userPW = "haha";
            }

            return LogMeIn;
        }
    }
}



I am new on Object oriented programming and

loginclass.AccountLogin();



keeps giving me an error
No over load for method 'AccountLogin' takes 0 arguments
how can I fix this

解决方案

What, what could possibly be unclear? This is not even related to OOP. You method Login.AccountLogin(WebLogin) expects one parameter of the type WebLogin. There is no a parameterless method with the same name, Login.AccountLogin(). Nevertheless, you are trying, without explanation of any reasons, to call AccountLogin(), that is, some non-existing method. You are trying that, no one else. And you are asking how to "fix this". There is nothing to fix. You need to write what you want to write, not something random.

Just a side note: amazing name for the field of the type Login: loginClass. I saw such silly cases when people named some class using the word "class" in it, or "application" in a name of the executable file, but class in the name of the instance of the class… You need to understand that names should be reasonable, express the semantic of what they are used for, use correctly spelled English words. This is important, because, otherwise, when you read you own code months or year later, you won't be able to understand it.

—SA


Try this


protected void btnLog_Click(object sender, EventArgs e)
       {
           WebLogin weblogin = new WebLogin();
           weblogin.UserID = UserID;
           weblogin.UserPW = UserPW;
           weblogin.UserLevel = UserLevel;
           loginclass.AccountLogin(weblogin);
       }


Error is itself self-explanatory,

No over load for method 'AccountLogin' takes 0 arguments

.
And your method takes WebLogin as an argument(parameter) to the function.

protected void btnLog_Click(object sender, EventArgs e)
{
    WebLogin wl = new WebLogin()
    wl.UserID = UserID;
    wlUserPW = userPW
    loginclass.AccountLogin(wl);
}


Not tested on IDE, but should work, ;)

-KR


这篇关于没有重载方法需要0参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆