Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 索引超出范围。必须为非负数且小于集合的大小_C#_Asp.net_Indexing - Fatal编程技术网

C# 索引超出范围。必须为非负数且小于集合的大小

C# 索引超出范围。必须为非负数且小于集合的大小,c#,asp.net,indexing,C#,Asp.net,Indexing,我已经看了20篇其他的帖子寻求帮助,但似乎没有一篇是我想要的。我已经包括了下面的所有内容。我试着使它等于I,但仍然得到索引错误。我正在处理的数据库并不总是包含信息。即使数据库中没有任何内容,我如何使其返回 List<DataClassLibrary.LineData> ScaleGroup1and3 = list.FindAll(ld => ld.ScaleGroup == DataClassLibrary.ScaleGroup.GROUP_1 ||

我已经看了20篇其他的帖子寻求帮助,但似乎没有一篇是我想要的。我已经包括了下面的所有内容。我试着使它等于I,但仍然得到索引错误。我正在处理的数据库并不总是包含信息。即使数据库中没有任何内容,我如何使其返回

List<DataClassLibrary.LineData> ScaleGroup1and3 = list.FindAll(ld => ld.ScaleGroup == DataClassLibrary.ScaleGroup.GROUP_1 ||
                                                            ld.ScaleGroup == DataClassLibrary.ScaleGroup.BOTH);

    List<DataClassLibrary.LineData> ScaleGroup2and3 = list.FindAll(ld => ld.ScaleGroup == DataClassLibrary.ScaleGroup.GROUP_2 ||
                                                        ld.ScaleGroup == DataClassLibrary.ScaleGroup.BOTH);

    Label[] Group1and3ItemLabels = new Label[8] { L1, L7, L13, L19, L25, L31, L37, L43 };
    Label[] Group1and3BrandLabels = new Label[8] { L2, L8, L14, L20, L26, L32, L38, L44 };
    Label[] Group1and3RacksLabels = new Label[8] { L3, L9, L15, L21, L27, L33, L39, L45 };
    Label[] Group1and3CasesLabels = new Label[8] { L50, L51, L53, L55, L57, L59, L61, L63};

    Label[] Group2and3ItemLabels = new Label[] { L4, L10, L16, L22, L28, L34, L40, L46 };
    Label[] Group2and3BrandLabels = new Label[] { L5, L11, L17, L23, L29, L35, L41, L47 };
    Label[] Group2and3rackslabels = new Label[] { L6, L12, L18, L24, L30, L36, L42, L48 };
    Label[] Group2and3CasesLabels = new Label[] { L49, L52, L54, L56, L58, L60, L62, L64 };

    for (int i = 0; i <= ScaleGroup1and3.Count; i++)
    {
            Group1and3ItemLabels[i].Text = list[i].ItemCode;
            Group1and3BrandLabels[i].Text = list[i].BrandCode;
            Group1and3CasesLabels[i].Text = list[i].CasesRemaining.ToString();
    }

    for (int i = 0; i <= ScaleGroup2and3.Count; i++)
    {
        Group2and3ItemLabels[i].Text = list[i].ItemCode;
        Group2and3BrandLabels[i].Text = list[i].BrandCode;
        Group2and3CasesLabels[i].Text = list[i].CasesRemaining.ToString();
    }
List ScaleGroup 1和3=List.FindAll(ld=>ld.ScaleGroup==DataClassLibrary.ScaleGroup.GROUP\u 1||
ld.ScaleGroup==DataClassLibrary.ScaleGroup.BOTH);
List ScaleGroup2and3=List.FindAll(ld=>ld.scalegroup2==DataClassLibrary.scalegroup2.group2||
ld.ScaleGroup==DataClassLibrary.ScaleGroup.BOTH);
Label[]Group1and3ItemLabels=新标签[8]{L1、L7、L13、L19、L25、L31、L37、L43};
Label[]group1和3brandlabels=新标签[8]{L2,L8,L14,L20,L26,L32,L38,L44};
Label[]group1和3rackslabels=新标签[8]{L3、L9、L15、L21、L27、L33、L39、L45};
Label[]group1和3caseslabels=新标签[8]{L50、L51、L53、L55、L57、L59、L61、L63};
Label[]Group2and3ItemLabels=新标签[]{L4、L10、L16、L22、L28、L34、L40、L46};
Label[]Group2and3BrandLabels=新标签[]{L5、L11、L17、L23、L29、L35、L41、L47};
Label[]Group2and3rackslabels=新标签[]{L6、L12、L18、L24、L30、L36、L42、L48};
Label[]Group2and3CasesLabels=新标签[]{L49、L52、L54、L56、L58、L60、L62、L64};

对于(int i=0;iChange
确保
scalegroup1和3
scalegroup2和3
具有不超过8个元素,并且
声明应如下所示:

for (int i = 0; i < ScaleGroup1and3.Count; i++)

for (int i = 0; i < ScaleGroup2and3.Count; i++)
for(int i=0;i
错误出现在哪一行?i@Plue group1和3ItemLabels[i]。Text=list[i].ItemCode;@Kpt.Khaos:我有8个元素,0-7。通过0-8==crash循环。这没有意义?不,我说的是@NiklasArbin所说的。当最后一个元素是元素7时,你不能为元素8编制索引。你有8个元素,但第一个元素是0。如果你从0增加到小于计数的1(<而不是当只有一条记录时能够返回?@Kpt.Khaos,是的。这一条记录的索引为0,而
Count
将为1,这意味着循环将只执行一次迭代,i等于0。如果i等于1怎么办?当数据库中只有一条记录时,我必须调整它,因为Count和index=1。但是我不会nt等于1,因为它是一个严格的小于,而不是小于或等于。我只有在计数为1时才能达到0。计数和索引永远不会同时为1。如果计数为1,则集合中只有一个元素,它将位于索引0处。db可以有数千个值,我只需要前八名,因此标签[]Group1and3ItemLabels=新标签[8]{L1、L7、L13、L19、L25、L31、L37、L43};
ScaleGroup1and3[ScaleGroup1and3.Count]
for (int i = 0; i < ScaleGroup1and3.Count; i++)

for (int i = 0; i < ScaleGroup2and3.Count; i++)