Type.GetArrayRank Method
.NET Framework 3.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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: