Article ID: 311156 - View products that this article applies to.
This article was previously published under Q311156
When you compile a Visual C# .NET console application, you may receive the following error message:
NOTE: The CS1502 error message is always accompanied by the CS1503 error message:
error CS1502: The best overloaded method match for 'declaration' has some invalid arguments
error CS1503: Argument 'arg': cannot convert from 'type1' to 'type2'
The argument types that are passed to the function do not match the parameter types of that function. If the called function is overloaded, none of the overloaded versions has a signature that matches the argument types that are passed.
To resolve this problem, do any of the following:
In the following sample Visual C# .NET console application, the Test function has two overloaded versions. The first version takes only an int type. The second version expects an int type as its first argument and a string type as its second argument. However, in the Main function, the first argument that is passed (nNum) is a string type. Neither of the two overloaded Test functions takes a string type as the first parameter.
One way to resolve the error is to declare nNum as an integer, as follows:
Another solution is to convert the string into an integer before you call the Test function. The following code resolves the compiler error and produces the desired result:
Contact us for more help
Connect with Answer Desk for expert help.