C#中ArrayList类的Count属性是什么?
ArrayList类中的Count属性对ArrayList中的元素数进行计数。
首先,将元素添加到ArrayList-
ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); arrList.Add(34);
然后获取数组列表的数量-
arrList.Count
以下是在C#中实现Count属性的代码-
示例
using System;
using System.Collections;
class Demo {
public static void Main() {
ArrayList arrList = new ArrayList();
arrList.Add(98);
arrList.Add(55);
arrList.Add(65);
arrList.Add(34);
Console.WriteLine("Count = " + arrList.Count);
}
}输出结果
Count = 4