Type.GetArrayRank Method
.NET Framework 2.0
Gets the number of dimensions in an Array.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
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 ); } }
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.
Community Additions
ADD
Show: