C#でジャグ配列の長さとランクを見つける方法は?
まず、ジャグ配列を設定します。
int[][] arr = new int[][] {
new int[] {
0,
0
}, new int[] {
1,
2
},
new int[] {
2,
4
}, new int[] {
3,
6
}, new int[] {
4,
8
}
}; 次に、GetLowerBound()、GetUpperBound()、およびRankプロパティを使用して、次のコードに示すように配列の長さとランクを取得します-
例
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
-
C#で配列の次元数をどのように見つけますか?
配列の次元数を見つけるには、Rankプロパティを使用します。 arr.Rank ここで、arrは配列です- int[,] arr = new int[3,4]; 含まれている行と列も取得する場合は、GetLengthプロパティ-を使用します。 arr.GetLength(0); arr.GetLength(1); 以下は完全なコードです- 例 using System; class Program { static void Main() { int[,] arr = new int[3,4]; &nb
-
C#で配列の長さをどのように見つけますか?
配列の長さを見つけるには、Array.Length()メソッドを使用します。 例 例を見てみましょう- using System; class Program { static void Main(){ int[] arr = new int[10]; // finding length int arrLength = arr.Length; Console.WriteLine("Lengt