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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version