What is the difference between Array.GetLength() and Array.Length?

前端 未结 5 1705
自闭症患者
自闭症患者 2020-12-13 08:51

How do you use the Array.GetLength function in C#?

What is the difference between the Length property and the GetLength functi

5条回答
  •  独厮守ぢ
    2020-12-13 09:37

    GetLength returns the length of a specified dimension of a mulit-dimensional array.

    Length returns the sum of the total number of elements in all the dimensions.

    • For a single-dimensional array, Length == GetLength(0)
    • For a two-dimensional array, Length == GetLength(0) * GetLength(1)

    etc.

提交回复
热议问题