ArrayList

The ArrayList works the same as Array but it can dynamically resize and has methods to
add and remove elements in the collection
It has the following methods:

- Add() method to add the elements

- Remove () method to remove the elements

Example 3: ArrayList collection adding and removing the element.

 

using System;
namespace SampleProgram {
  class MySample {
    public static void Main(string[] args) {
      ArrayList arrList = new ArrayList();
      arrList.Add(100);
      arrList.Add(true);
      arrList.Add( " Hi ");
      arrList.Add(23.5);
      foreach(object m in arrList) {
        Console.Write($ " {
          m
        } ");
      }
      Console.WriteLine();
      Console.WriteLine(arrList.Capacity);
      arrList.Remove(true);
      foreach(object m in arrList) {
        Console.Write($ " {
          m
        } ");
      }
    }
  }
}

 

The output will be:

100 True Hi 23.5
4
100 Hi 23.5

 

Related Tutorials