What is the Count property of ArrayList class in C#?


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# −

Example

 Live Demo

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);

   }
}

Output

Count = 4

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

194 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements