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

前端 未结 5 1768
自闭症患者
自闭症患者 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:36

    The .Length property returns the number of elements in an array, whether it be one dimensional or multidimensional. That is a 2x6 array will have length of 12.

    The .GetLength(0) method returns number of elements in the row direction in a multidimensional array. For a 2x6 array that is 2.

    The .GetLength(1) method returns number of elements in the column direction in a multidimensional array. For a 2x6 array that is 6.

    These do not return an actual element value, as stated by the chosen answer above.

提交回复
热议问题