Type.GetArrayRank 메서드

정의

배열의 차원 수를 가져옵니다.

public:
 abstract int GetArrayRank();
public:
 virtual int GetArrayRank();
public abstract int GetArrayRank();
public virtual int GetArrayRank();
abstract member GetArrayRank : unit -> int
abstract member GetArrayRank : unit -> int
override this.GetArrayRank : unit -> int
Public MustOverride Function GetArrayRank () As Integer
Public Overridable Function GetArrayRank () As Integer

반품

현재 형식의 차원 수를 포함하는 정수입니다.

구현

예외

이 메서드의 기능은 기본 클래스에서 지원되지 않으며 대신 파생 클래스에서 구현되어야 합니다.

현재 형식이 배열이 아닙니다.

예제

다음 예제에서는 배열의 차원 수를 표시합니다.

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

try
    let myArray = Array3D.zeroCreate 2 2 3
    myArray[0, 0, 0] <- 12
    myArray[0, 0, 1] <- 2
    myArray[0, 0, 2] <- 35

    myArray[0, 1, 0] <- 300
    myArray[0, 1, 1] <- 78
    myArray[0, 1, 2] <- 33
    
    myArray[1, 0, 0] <- 92
    myArray[1, 0, 1] <- 42
    myArray[1, 0, 2] <- 135
    
    myArray[1, 1, 0] <- 30
    myArray[1, 1, 1] <- 7
    myArray[1, 1, 2] <- 3
    let myType = myArray.GetType()

    printfn "Contents of myArray: {{{12,2,35},{300,78,33}},{{92,42,135},{30,7,3}}}"
    printfn $"myArray has {myType.GetArrayRank()} dimensions."
with 
| :? NotSupportedException as e ->
    printfn "NotSupportedException raised."
    printfn $"Source: {e.Source}"
    printfn $"Message: {e.Message}"
| e ->
    printfn "Exception raised."
    printfn $"Source: {e.Source}"
    printfn $"Message: {e.Message}"
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
End Class

적용 대상

추가 정보