C#最好的重载方法匹配...有一些无效的参数

Moh*_*mad 8 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();
    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;
    }
Run Code Online (Sandbox Code Playgroud)

这是注册按钮单击时的webform

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);
Run Code Online (Sandbox Code Playgroud)

....

这是错误:

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

请帮帮我.

Mar*_*cik 16

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


Ser*_*rvy 14

txt_Name.ToString解析为引用该ToString方法的方法组.它没有打电话 ToString.要做到这一点,你需要写txt_Name.ToString().话虽如此,你也不想这样做.该ToString方法TextBox不返回控件的文本.该Text物业是你如何获取文本,所以你要这样写:txt_Name.Text.

最后,你应该避免使用这么多参数的函数.当你有这么多论点时遇到的错误时,试图确定错误是多么困难; 它有很多方法可以关闭.相反,RegistrationClass应该只具有每个值的属性,然后调用者可以单独设置每个属性.这将更容易使用.