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

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.


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.

Tags:

C#

Asp.Net