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);
}
}
}