Array.Rank 属性 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 Array 的秩(维数)。 例如,一维数组返回 1,二维数组返回 2,依次类推。
public:
 property int Rank { int get(); };public int Rank { get; }member this.Rank : intPublic ReadOnly Property Rank As Integer属性值
Array 的秩(维数)。
示例
以下示例初始化一维数组、二维数组和一个交错数组,并检索 Rank 每个数组的属性。
using System;
public class Example
{
   public static void Main()
   {
      int[] array1 = new int[10];
      int[,] array2= new int[10,3];
      int[][] array3 = new int[10][];
      Console.WriteLine("{0}: {1} dimension(s)",
                        array1.ToString(), array1.Rank);
      Console.WriteLine("{0}: {1} dimension(s)",
                        array2.ToString(), array2.Rank);
      Console.WriteLine("{0}: {1} dimension(s)",
                        array3.ToString(), array3.Rank);
   }
}
// The example displays the following output:
//       System.Int32[]: 1 dimension(s)
//       System.Int32[,]: 2 dimension(s)
//       System.Int32[][]: 1 dimension(s)
let array1 = Array.zeroCreate<int> 10
let array2 = Array2D.zeroCreate<int> 10 3
let array3 = Array.zeroCreate<int[]> 10
printfn $"{array1}: {array1.Rank} dimension(s)"
printfn $"{array2}: {array2.Rank} dimension(s)"
printfn $"{array3}: {array3.Rank} dimension(s)"
// The example displays the following output:
//       System.Int32[]: 1 dimension(s)
//       System.Int32[,]: 2 dimension(s)
//       System.Int32[][]: 1 dimension(s)
Module Example
   Public Sub Main()
      Dim array1(9) As Integer
      Dim array2(9,2) As Integer
      Dim array3(9)() As Integer
      Console.WriteLine("{0}: {1} dimension(s)",
                        array1.ToString(), array1.Rank)
      Console.WriteLine("{0}: {1} dimension(s)",
                        array2.ToString(), array2.Rank)
      Console.WriteLine("{0}: {1} dimension(s)",
                        array3.ToString(), array3.Rank)
   End Sub
End Module
' The example displays the following output:
'       System.Int32[]: 1 dimension(s)
'       System.Int32[,]: 2 dimension(s)
'       System.Int32[][]: 1 dimension(s)
注解
例如,以下代码创建三个维度的数组,其 Rank 值为 3 的属性。
Dim TDArray(0,0,0) As Integer
int[,,] TDArray = new int[1,1,1];
(数组的交错数组) 是一维数组;其 Rank 属性的值为 1。
检索此属性的值的运算复杂度为 O(1)。