什么是基于索引的 I/O ArrayList 集合(在 C# 中)?
ArrayList 类表示一个有序对象的集合,可单独进行索引。它是数组的一种替代方案。
下表列出了 ArrayList 类的常用属性(部分)−
| 序号 | 属性和说明 |
|---|---|
| 1 | 容量 获取或设置 ArrayList 可容纳的元素数量。 |
| 2 | 计数 获取 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