-4 c# arrays methods int compiler-errors
我有简单的方法.我无法弄清楚它为什么会抛出错误.提前致谢!
public static int[] Shift(int[] a)
{
if (a == null) return -1;
...
}
Run Code Online (Sandbox Code Playgroud)
编译器抛出以下错误:
无法隐式转换
int为int[]
小智 9
如果您的数组为null,则返回int.该函数期望int [].您可以返回null或空数组.
您正在尝试返回和int但是您的方法需要一组int.在这种情况下你想要回报什么?
你可以返回一个空数组
return new int[]{};
Run Code Online (Sandbox Code Playgroud)
或包含-1的数组
return new int[]{-1};
Run Code Online (Sandbox Code Playgroud)