Export (0) Print
Expand All
Expand Minimize

Type.GetArrayRank Method

Gets the number of dimensions in an Array.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Overridable Function GetArrayRank As Integer
'Usage
Dim instance As Type
Dim returnValue As Integer

returnValue = instance.GetArrayRank
public int GetArrayRank ()
public function GetArrayRank () : int

Return Value

An Int32 containing the number of dimensions in the current Type.

Exception typeCondition

NotSupportedException

The functionality of this method is unsupported in the base class and must be implemented in a derived class instead.

ArgumentException

The current Type is not an array.

The following example displays the number of dimensions in an array.

Imports System
Imports Microsoft.VisualBasic

Class MyArrayRankSample
    Public Shared Sub Main()
        Try
            Dim myArray(,,) As Integer = {{{12, 2, 35}, {300, 78, 33}}, {{92, 42, 135}, {30, 7, 3}}}
            Dim myType As Type = myArray.GetType()
            Console.WriteLine("Contents of myArray: {{{12,2,35},{300,78,33}},{{92,42,135},{30,7,3}}}")
            Console.WriteLine("myArray has {0} dimensions.", myType.GetArrayRank())
        Catch e As NotSupportedException
            Console.WriteLine("NotSupportedException raised.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        Catch e As Exception
            Console.WriteLine("Exception raised.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        End Try
    End Sub 'Main 
End Class 'MyArrayRankSample

import System.*;

class MyArrayRankSample
{
    public static void main(String[] args)
    {
        try {
            int myArray[, ,] = new int[,,] { { { 12, 2, 35 } ,
                { 300, 78, 33 } } , { { 92, 42, 135 } , { 30, 7, 3 } } };
            Type myType = myArray.GetType();

            Console.WriteLine("Contents of myArray: {{{12,2,35},{300,78,33}},"
                +"{{92,42,135},{30,7,3}}}");
            Console.WriteLine("myArray has {0} dimensions.",
                System.Convert.ToString(myType.GetArrayRank()));
        }
        catch (NotSupportedException e) {
            Console.WriteLine("NotSupportedException raised.");
            Console.WriteLine("Source: " + e.get_Source());
            Console.WriteLine("Message: " + e.get_Message());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception raised.");
            Console.WriteLine("Source: " + e.get_Source());
            Console.WriteLine("Message: " + e.get_Message());
        }
    } //main
} //MyArrayRankSample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft