我尝试如下
public int[] GetCompletedCalls()
{
int[] minMax = int[2];
minMax[0] = countCompleted;
minMax[1] = countPendings;
return minMax;
}
但是在声明数组变量时抛出错误:无效 表达词“ int”
答案 0 :(得分:5)
您需要使用new
关键字:
int[] minMax = new int[2];
答案 1 :(得分:1)
有多种方法可以实现这一目标。最简单的方法只需要进行一次校正:
int[] minMax = int[2];
应该是
int[] minMax = new int[2];
另一个机会是这样做:
return new [] { countCompleted, countPendings};
还是这个:
public void GetCompletedCalls(out int completed, out int pending)
{
completed = countCompleted;
pending = countPendings;
}
或使用元组代替的代码(需要C#7):
public (int, int) GetCompletedCalls()
{
return (countCompleted, countPendings);
}