C#
 Computer >> コンピューター >  >> プログラミング >> 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
}
};

次に、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

  1. C#を使用して文字列の長さを計算するにはどうすればよいですか?

    C#のString.Lengthプロパティを使用して、文字列の長さを取得します。 str.Length このプロパティは、文字列内の単語を計算し、指定された文字列の長さを表示します。たとえば、文字列Amitの文字数は4文字です- string str = "Amit"; 例 以下は、文字列の長さを計算するためのC#プログラムです- using System; using System.Collections; namespace Demo {    class Program {       static void

  2. C#で配列の長さをどのように見つけますか?

    配列の長さを見つけるには、Array.Length()メソッドを使用します。 例 例を見てみましょう- using System; class Program {    static void Main(){       int[] arr = new int[10];       // finding length       int arrLength = arr.Length;       Console.WriteLine("Lengt