集合类是用于数据存储和检索的专门类。这些类为堆栈,队列,列表和哈希表提供支持。大多数集合类实现相同的接口。
以下是C#中的收集类-
ArrayList类表示可以单独索引的对象的有序集合。
哈希表使用键来访问集合中的元素。
它使用键和索引来访问列表中的项目。
它使用值1和0表示二进制表示形式的数组。
它表示对象的后进先出集合。
它代表对象的先进先出集合。
让我们看一下C#中ArrayList类的示例-
using System;
using System. Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
ArrayList al = new ArrayList();
al.Add(99);
al.Add(76);
al.Add(87);
al.Add(46);
al.Add(55);
Console.WriteLine("Capacity: {0} ", al.Capacity);
Console.WriteLine("Count: {0}", al.Count);
Console.Write("Elements: ");
foreach (int i in al) {
Console.Write(i + " ");
}
Console.WriteLine();
Console.ReadKey();
}
}
}
输出结果
Capacity: 8
Count: 5
Elements: 99 76 87 46 55