Difference between array.GetLength(0) and array.GetUpperBound(0)

后端 未结 6 1374
攒了一身酷
攒了一身酷 2020-12-28 15:02

What is the difference between these two methods and when would you use one instead of the other?

int[,] array = new int[4,3];
int length0 = array.GetLength(         


        
6条回答
  •  旧巷少年郎
    2020-12-28 15:42

    if lower bound of your array is 0 then you can use either of them without any confusion but i would recommend array.length-1 as it is widely used. however, if the lower bound of your array is less than 0 then you should use array.GetUpperBound(0) because in this case array.length-1 != array.getUpperBound(0)

提交回复
热议问题