Type::GetArrayRank Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the number of dimensions in an array.

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

public:
virtual int GetArrayRank()

Return Value

Type: System::Int32

An integer that contains the number of dimensions in the current type.

Exception Condition
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.

using namespace System;
int main()
{
   try
   {
      array<Int32, 3>^myArray = gcnew array<Int32,3>(3,4,5);
      Type^ myType = myArray->GetType();
      Console::WriteLine( "myArray has {0} dimensions.", myType->GetArrayRank() );
   }
   catch ( NotSupportedException^ e ) 
   {
      Console::WriteLine( "NotSupportedException raised." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception raised." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }

}

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: