Iterate through 2 dimensional array c#

后端 未结 7 1522
悲&欢浪女
悲&欢浪女 2020-12-03 16:37
for(int k=0;k <= odds.GetLength(-1);k++)

The above line of code is supposed to iterate through a two dimensional array of type Double but keeps

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 17:14

    I see one or two problems depending on how you intend to use it:

    First off, GetLength(ind dimension) returns length of specified dimension, starting from 0. In case of a two-dimensional array, correct indices would be 0 and 1.

    The second problem is that you are doing <= instead of < for loop condition, which might also go out of bounds since last index is length-1 and not length.

    StriplingWarrior and Gilad Naaman posted code examples so I'll skip that.

提交回复
热议问题