Array.Rank 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 . 的 Array排名(维度数) 例如,一维数组返回 1、二维数组返回 2 等。
public:
property int Rank { int get(); };
public int Rank { get; }
member this.Rank : int
Public 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) 操作。