C# 中基於索引的 I/O ArrayList 集合是什麼?
ArrayList 類表示可獨立索引的物件的有序集合。它是陣列的替代方案。
下表列出了 ArrayList 類的一些常用屬性
| 序號 | 屬性描述 |
|---|---|
| 1 | Capacity 獲取或設定ArrayList可以包含的元素數。 |
| 2 | Count 獲取ArrayList中實際包含的元素數。 |
| 3 | IsFixedSize 獲取一個值,指示ArrayList是否具有固定大小。 |
| 4 | IsReadOnly 獲取一個值,指示ArrayList是否是隻讀的。 |
| 5 | Item 獲取或設定指定索引處的元素。 |
以下示例顯示如何在 C# 中使用 ArrayList 並查詢容量。預設容量為 4。
示例
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
ArrayList x = new ArrayList();
x.Add(45);
x.Add(53);
x.Add(12);
x.Add(88);
Console.WriteLine("Capacity: {0} ", x.Capacity);
}
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP