日期:2014-05-17  浏览次数:20495 次

数组超出范围?
C# code


                int[] Iday =null;
                for (int a = 0; a <= ehour; a++)
                {
                    Iday[a] = shour;
                    shour++;
                }


这样写为什么不对?

------解决方案--------------------
没声明 Iday 的大小

不定长度时候,最好用List<int> 写法
------解决方案--------------------
数组还没初始化
C# code

                int[] Iday = new int[ehour+1];
                for (int a = 0; a <= ehour; a++)
                {
                    Iday[a] = shour;
                    shour++;
                }

------解决方案--------------------
C# code
        int[] Iday = null;
        for (int a = 0; a < Iday.Length; a++)
        {
            Iday[a] = shour;
            shour++;
        }