【发布时间】:2013-10-16 11:49:34
【问题描述】:
我已经在许多网站上搜索了解决方案,但我不能完全理解重载方法的概念,至少对于这个方法来说不是,因为我看不出我哪里出了问题。每当我尝试调用下面所述的方法时,我都会收到此错误 - “方法'arrayCalculator' 没有重载需要 0 个参数”。我希望你能帮助我解决这个问题。谢谢。
public class Calculations
{
public static int[] arrayCalculator(object sender, EventArgs e, int m)
{
int i;
int[] result = new int[9];
int[] timesTable = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for (i = 0; i <= 9; i++)
{
result[i] = m * timesTable[i];
System.Diagnostics.Debug.WriteLine("Calculation successful: " + m + " * " + timesTable[i] + " = " + result[i] + ".");
}
return result; // returns int result[]
}
}
【问题讨论】:
-
显示调用代码。
-
这段代码没有错。你怎么称呼它?这就是问题所在!
-
您可能键入“arrayCalculator();”在调用时,但您还需要提供三个参数,如“arrayCalculator();”不向方法发送任何参数。
标签: c# arguments overloading