我如何確定我的 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP