索引超出了数组界限。我把数组设的那么大,索引为什么会越界呢。到底哪里出错,初学者。谢谢!
int [,]chengshi={{9,7,3,6,8,7,8,2,8,8},{5,6,5,9,6,5,6,1,8,6},{10,7,7,7,7,8,8,6,7,7},{9,9,8,6,10,10,8,5,9,7},{5,8,9,5,6,7,10,7,7,10},{5,9,10,4,7,8,9,4,7,10},{4,8,7,3,4,5,6,7,5,7},{10,8,7,10,6,7,8,4,9,8},{6,8,7,6,6,
6,7,8,5,5},{4,7,8,8,7,9,8,3,6,9},{7,9,8,10,8,8,8,4,8,9}};
public void fangfa()
{
//下面的十个track代表各个游标的对应的值
int zhi1 = track1.Value;
int zhi2 = track2.Value;
int zhi3 = track3.Value;
int zhi4 = track4.Value;
int zhi5 = track5.Value;
int zhi6 = track6.Value;
int zhi7 = track7.Value;
int zhi8 = track8.Value;
int zhi9 = track9.Value;
int zhi10 = track10.Value;
int[] zhi = { zhi1, zhi2, zhi3, zhi4, zhi5, zhi6, zhi7, zhi8, zhi9, zhi10 };
int[] chazhi = new int[20]; //10个指标对应的差值
double[] pingfang = new double[20];//10个指标差值的平方
double[] zuizhong = new double[1000];//1000个城市容量
int i;
for (i = 0; i < chengshi.Length; i++)
{
zuizhong[i] = 0;
for (int j = 0; j < 10; j++)
{
chazhi[j] = chengshi[i,j]- zhi[j];//提示出错:索引超出了数组界限。
pingfang[j] = Math.Pow(chazhi[j], 2);//各个差值的平方
zuizhong[i] = zuizhong[i] + pingfang[j];//指标总不至于比城市数量还多吧
}