次の方法で共有


Type.GetArrayRank メソッド

Array の次元数を取得します。

Public Overridable Function GetArrayRank() As Integer
[C#]
public virtual int GetArrayRank();
[C++]
public: virtual int GetArrayRank();
[JScript]
public function GetArrayRank() : int;

戻り値

現在の Type の次元数を保持している Int32

例外

例外の種類 条件
NotSupportedException このメソッドの機能が基本クラスでサポートされないため、代わりに派生クラスで実装する必要があります。
ArgumentException 現在の Type が配列ではありません。

使用例

[Visual Basic, C#, C++] 配列の次元の数を表示する例を次に示します。

 
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

[C#] 
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);
        }      
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

int main() {
   try {
      Int32 myArray[,,] = new Int32[3,4,5];
      Type*  myType = myArray->GetType();

      Console::WriteLine(S"myArray has {0} dimensions.",__box( myType->GetArrayRank()));
   } catch (NotSupportedException* e) {
      Console::WriteLine(S"NotSupportedException raised.");
      Console::WriteLine(S"Source: {0}", e->Source);
      Console::WriteLine(S"Message: {0}", e->Message);
   } catch (Exception* e) {
      Console::WriteLine(S"Exception raised.");
      Console::WriteLine(S"Source: {0}", e->Source);
      Console::WriteLine(S"Message: {0}", e->Message);
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | Array | Rank