我如何確定我的 C# 陣列的長度


首先,設定一個數組 -

int[] arr = {6, 3, 8, 4};

現在,使用 Length 屬性獲取陣列的長度 -

arr.Length

讓我們看看完整的程式碼 -

示例

 即時預覽

using System;
namespace Demo {
   public class Demo {
      public static void Main(string[] args) {
         int[] arr = {6, 3, 8, 4};
         Console.WriteLine("Array...");
         foreach (int i in arr) {
            Console.Write(i + " ");
         }
         Console.WriteLine("
Size of Array: "+arr.Length);       }    } }

輸出

Array...
6 3 8 4
Size of Array: 4

更新於: 2020-06-22

149 人瀏覽

開啟你的 職業

完成課程,獲得認證

開始
廣告
© . All rights reserved.