Thuộc tính Count trong ArrayList đếm số phần tử thực tế đang có trong danh sách.
Ví dụ
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);
}
}
Kết quả
Count = 4
Lưu ý: ArrayList là non-generic (lưu object), gây boxing/unboxing. Nên dùng List<T> trong System.Collections.Generic cho type-safe và hiệu năng tốt hơn.