标题:索引超出了数组界限。我把数组设的那么大,索引为什么会越界呢。到底哪里出 ...
只看楼主
云の翼
Rank: 1
等 级:新手上路
帖 子:17
专家分:3
注 册:2012-6-25
结帖率:87.5%
已结贴  问题点数:20 回复次数:5 
索引超出了数组界限。我把数组设的那么大,索引为什么会越界呢。到底哪里出错,初学者。谢谢!
  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];//指标总不至于比城市数量还多吧
                }
搜索更多相关主题的帖子: public 
2013-05-31 04:09
shangsharon
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
威 望:7
帖 子:221
专家分:1261
注 册:2012-3-25
得分:3 
chazhi[j] = chengshi[i,j]- zhi[j];//提示出错:索引超出了数组界限。
知道i的最大值是多少吗? chengshi.Length
知道chengshi.Length的值是多少吗?
肯定不是10.
2013-05-31 11:53
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
得分:3 
好像你数组与你定义的长度不相符合,肯定是多了

慢慢前进走,不求一步登天,只求慢慢前进
2013-05-31 12:20
csharpluntan
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:7
帖 子:197
专家分:1122
注 册:2013-4-24
得分:2 
2楼正解

投之以桃,报之以李
2013-05-31 13:39
moridiansha
Rank: 6Rank: 6
来 自:承德
等 级:侠之大者
威 望:4
帖 子:254
专家分:417
注 册:2009-10-21
得分:12 
chazhi[j] = chengshi[i,j]- zhi[j];//提示出错:索引超出了数组界限。
chengshi是个二维数组,length的值应该是所有元素的个数,所以远远大于10

www.qysy.tk
2013-05-31 14:11
不会哭的面具
Rank: 2
等 级:论坛游民
帖 子:10
专家分:17
注 册:2012-11-25
得分:0 
11个多了一个?
2013-06-07 23:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-412645-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.145402 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved