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

后端 未结 6 1281
攒了一身酷
攒了一身酷 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:24

    GetUpperBound returns the highest index in the array, the GetLength returns the number of elements of the array.

    i.e. GetUpperBound = GetLength - 1

提交回复
热议问题