如何找到 C# 中陣列的長度?


要查詢陣列的長度,請使用 Array.Length() 方法。

示例

讓我們看一個示例 -

 即時演示

using System;
class Program {
   static void Main(){
      int[] arr = new int[10];
      // finding length
      int arrLength = arr.Length;
      Console.WriteLine("Length of the array: "+arrLength);
   }
}

輸出

Length of the array: 10

上面我們有一個數組 -

int[] arr = new int[10];

現在,要查詢長度,我們使用了 Length() 方法 -

int arrLength = arr.Length;

更新時間: 2020-06-20

17000+ 瀏覽

開啟你的職業生涯

完成課程,獲得認證

入門
廣告