如何使用屬性查詢鋸齒陣列的長度?
首先,宣告並初始化鋸齒陣列。
int[][] arr = new int[][] {
new int[] {
0,
0
}, new int[] {
1,
2
},
new int[] {
2,
4
}, new int[] {
3,
6
}, new int[] {
4,
8
}
};現在使用 length 屬性來獲取長度。
arr.Length
以下是完整程式碼 −
示例
using System;
public class Program {
public static void Main() {
int[][] arr = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }, new int[]{ 4, 8 } };
// Length
Console.WriteLine("Length:"+arr.Length);
Console.WriteLine("Upper Bound: {0}",arr.GetUpperBound(0).ToString());
Console.WriteLine("Lower Bound: {0}",arr.GetLowerBound(0).ToString());
Console.WriteLine("Dimensions of Array : " + arr.Rank);
}
}輸出
Length:5 Upper Bound: 4 Lower Bound: 0 Dimensions of Array : 1
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP