Type.GetArrayRank 方法

获取 Array 中的维数。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overridable Function GetArrayRank As Integer
用法
Dim instance As Type
Dim returnValue As Integer

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

返回值

包含当前 Type 中维数的 Int32

异常

异常类型 条件

NotSupportedException

此方法的功能在基类中不受支持,而必须在派生类中实现。

ArgumentException

当前 Type 不是数组。

示例

下面的示例显示数组中的维数。

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
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);
        }      
    }
}
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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Type 类
Type 成员
System 命名空间
Array 类
Array.Rank 属性