311156 PRB: Compile Visual C # .NET Console Application When Applications An Invalid Parameters (from MKBA)

xiaoxiao2021-03-06  75

The release number of this article has been CHS311156

Symptom When you compile the Visual C # .NET console application, you may receive the following error message:

ERROR CS1502: The Best Overloaded Method Match for 'Declaration' Has Some Invalid Arguments (Error CS1502: Maximum overload method with "Declaration" has some invalid parameters)

Remarks: CS1502 error message always appears together with the CS1503 error message:

Error CS1503: argument 'arg': Cannot Convert from 'Type1' to 'Type2' (Error CS1503: Parameter "Arg": Unable to convert from "Type1" to "Type2")

Cause The parameter type passing to the function does not match the parameter type of the function. If the called function is overloaded, there is no overload version of the signature that matches the passable parameter type.

Solution To resolve this issue, do one of the following:

Carefully check the type of parameters transmitted to ensure that this type matches the parameters of the called function. Correct any coding errors that may cause this issue. If appropriate, you can convert any mismatched parameters using the System.convert class. If suitable, forced to convert any mismatched parameter type to match the type required by the function. If appropriate, another overload version of the function can be defined to match the parameter type sent.

This phenomenon is designed to make.

MORE INFORMATION In the sample Visual C # .NET console application,

Test functions have two overload versions. The first version only uses one

Int type. The second version needs

INT type as its first parameter, one

String type as its second parameter. But when

In the main function, the first parameter transmitted (

Nnum) is

String type. These two overloaded

Test functions are not

String type as the first parameter.

Using system;

Namespace X

{

Public Class Ctest

{

Public static void test (int N1) {}

Public Static Void Test (INT N1, STRING STR) {}

Public static void main ()

{

String nnum = "1000";

Ctest.test (nnum, "string2"); // cs1502

}

}

} One way to correct this error is

NNum declares as an integer as follows:

INT nnum = 1000; another method is in calling

The string is converted to an integer before the TEST function. The following code can correct the compiler error and generate the desired result:

String nnum = "1000";

Int nnumconverted = system.convert.toint32 (nnum, 10);

CTest.test (nnumconverted, "string2"); // cs1502

The information in this article applies to:

Microsoft Visual C # .NET (2002)

Recent Updated: 2002-1-17 (1.0) Keyword KBPRB KBPROD2WEB KB311156

转载请注明原文地址:https://www.9cbs.com/read-108924.html

New Post(0)