The Count property in the ArrayList class counts the number of elements in the ArrayList.
Firstly, add elements to the ArrayList −
ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); arrList.Add(34);
Then get the count of the array list −
arrList.Count
The following is the code to implement Count property in C# −
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