C# 中 ArrayList 类的 Item 属性是什么?
csharpprogrammingserver side programming更新于 2025/10/12 2:22:17
使用 ArrayList 类的 Item 属性可以获取或设置 ArrayList 中指定索引处的元素。
Item 属性是一个索引器,因此无需添加属性名称即可使用它。
在下面的示例中,我们像以下语句一样使用它 −
Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]);
让我们查看完整的示例,了解如何使用 Item 属性。
示例
using System;
using System.Collections;
class Demo {
public static void Main() {
ArrayList arrList = new ArrayList();
arrList.Add(45);
arrList.Add(78);
arrList.Add(88);
Console.WriteLine("Total elements: "+arrList.Count);
Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]);
}
}
输出
Total elements: 3 Element 2 is "78"

