Type.GetArrayRank 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得陣列中的維度數目。
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 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 );
}
}
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);
}
}
}
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