C#与…匹配的最佳重载方法具有一些无效参数

C#与…匹配的最佳重载方法具有一些无效参数,c#,asp.net,C#,Asp.net,这是“注册时的网络表单”按钮单击 public class RegistrationClass { SqlConnection myConnection = new SqlConnection("Data Source=MOE-PC\\SQLEXPRESS;Initial Catalog=db_University;Integrated Security=True;Pooling=False"); ConnectionClass con = new ConnectionClass

这是“注册时的网络表单”按钮单击

public class RegistrationClass
{
    SqlConnection myConnection = new SqlConnection("Data Source=MOE-PC\\SQLEXPRESS;Initial Catalog=db_University;Integrated Security=True;Pooling=False");
    ConnectionClass con = new ConnectionClass();
    int ID , i;
    String fullName, motherName, gender, placeOfBirth, email, phone, adress, schoolDegree, languages, highSchool, faculty, major;

    public void setValues (String fullName1,String motherName1,String gender1,String placeOfBirth1,String email1,String phone1,String adress1, String faculty1,String major1,String schoolDegree1,String languages1,String highSchool1)
    {
        fullName = fullName1;
        motherName = motherName1;
        gender = gender1;
        placeOfBirth= placeOfBirth1;
        email =email1;
        phone= phone1;
        adress =adress1;
        faculty =faculty1;
        major =major1;
        schoolDegree =schoolDegree1;
        languages =languages1;
        highSchool = highSchool1;
    }
以下是错误:

与“CCharpApp.RegistrationClass.setValues(string,string,string,string,string,string,string,string,string,string,string,string)”匹配的最佳重载方法具有一些无效参数


txt\u Name.ToString
解析为引用
ToString
方法的方法组。它不调用
ToString
。为此,您需要编写
txt\u Name.ToString()
。话虽如此,你也不想这么做。
TextBox
ToString
方法不返回控件的文本。
Text
属性是获取文本的方式,因此需要编写:
txt\u Name.Text


最后,应该避免使用参数太多的函数。当有这么多的争论时,当你看到错误的时候,你就更难去判断什么是错的;有很多方法可以让它停止。相反,
RegistrationClass
应该只具有这些值中每个值的属性,然后调用方可以单独设置每个属性。这将非常容易使用。

动态变量作为参数传递到方法中时,也会发生这种情况。编译器编译时没有错误,可能有执行错误。

这就是为什么不应该有这么多参数的函数。此方法需要一些TLC。当传递方法组而不是字符串时,应用程序如何编译?@Loreno It…不…这就是OP发布编译器错误的原因。是的,谢谢分享,马丁。(DynamicObject,dynamicvar)类似的错误发生在我的身上,在我的例子中,类型是var
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Button_Register_Click(object sender, EventArgs e)
    {
        string lang = "";
        Classes.RegistrationClass R = new Classes.RegistrationClass();
        R.setValues(txt_Name.ToString, txt_MotherName.ToString, dropDown_Gender.ToString, dropDown_POB.ToString, txt_Email.ToString, txt_Phone.ToString, txt_Adress.ToString, DropDown_Faculty.ToString, DropDown_Major.ToString, dropDown_SchoolDegree.ToString, txt_Name.ToString, txt_HighSchool.ToString);