C# Array GetLength
Description
Array GetLength
gets a 32-bit integer that represents
the number of elements in the specified dimension of the Array.
Syntax
Array.GetLength
has the following syntax.
public int GetLength(
int dimension
)
Parameters
Array.GetLength
has the following parameters.
dimension
- A zero-based dimension of the Array whose length needs to be determined.
Returns
Array.GetLength
method returns A 32-bit integer that represents the number of elements in the specified
dimension.
Example
The following example shows how to use GetLength to display the dimensions of two arrays with different ranks.
using System;/*from w ww.j a v a2 s . c om*/
public class SamplesArray
{
public static void Main()
{
Array MyArray1 = Array.CreateInstance(typeof(int), 5);
Console.WriteLine( MyArray1.GetLength(1));
}
}
The code above generates the following result.