Type.GetArrayRank メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
配列の次元数を取得します。
public:
abstract int GetArrayRank();
public:
virtual int GetArrayRank();
C#
public abstract int GetArrayRank ();
C#
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 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 );
}
}
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);
}
}
}
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
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。