【发布时间】:2014-11-20 16:49:13
【问题描述】:
我正在使用 c#,但遇到了流动问题: 我之前为循环蚂蚁减速了高度变量,它说循环中不存在。
在这部分代码中,我希望程序存储除第一个之外的“data”数组的所有第三个元素,因此如果“data”数组如下所示:1,2,3,4,5 ,6,7,8,9,10,11,12... 我想得到:6,9,12...
static int[] tall()
{
int[] data = database();//recalling an array filled with numbers
int j = 0;
int[] height;
for (int i = 6; i < data.Length; )
{
i = i + 3;
j++;
height[j] = data[i];//Use of unassigned local variable 'height'
}
return height;
}
【问题讨论】:
-
我不确定 cycle 但你必须像
int[] height = new int[data.Length];或int[] height = new int[data.Length - 6];一样初始化你的数组