Type.GetArrayRank Method
.NET Framework 4.5
Gets the number of dimensions in an Array.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
| 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 System; class MyArrayRankSample { public static void Main() { 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.", myType.GetArrayRank()); } catch(NotSupportedException e) { Console.WriteLine("NotSupportedException raised."); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Message: " + e.Message); } catch(Exception e) { Console.WriteLine("Exception raised."); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Message: " + e.Message); } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.