Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# The best overloaded method match for ...has some invalid arguments

Tags:

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

This is the webform on register button click

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

Here is the error:

The best overloaded method match for 'CCharpApp.RegistrationClass.setValues(string,string,string,string,string,string,string,string,string,string,string,string)' has some invalid arguments.

like image 367
Mohammad Avatar asked Mar 10 '14 21:03

Mohammad


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

How old is the letter C?

The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.


2 Answers

This can also happen when a dynamic variable is passed into the method as an argument. The compiler compiles without an error, there can be an execution error.

like image 108
Martin Staufcik Avatar answered Oct 30 '22 17:10

Martin Staufcik


txt_Name.ToString resolves to a method group that refers to the ToString method. It doesn't call ToString. To do that you would need to write txt_Name.ToString(). Having said that, you don't want to do that either. The ToString method of TextBox does not return the text of the control. The Text property is how you get the text, so you want to write: txt_Name.Text.

Finally, you should avoid functions with so many arguments. It makes it much harder to try to determine what's wrong when you have the error that you are seeing when there are so many arguments; there are just so many ways that it could be off. Instead RegistrationClass should simply have properties of each of those values, and then the caller can set each property individually. This will be quite a lot easier to work with.

like image 30
Servy Avatar answered Oct 30 '22 16:10

Servy