C# ArrayList Add

Description

ArrayList Add adds an object to the end of the ArrayList.

Syntax

ArrayList.Add has the following syntax.


public virtual int Add(
  Object value
)

Parameters

ArrayList.Add has the following parameters.

  • value - The Object to be added to the end of the ArrayList. The value can be null.

Returns

ArrayList.Add method returns The ArrayList index at which the value has been added.

Example

The following code adds items to ArrayList and use foreach loop to check.


using System;/* w w w .j  a v a2s.c  om*/
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        ArrayList baseballTeams = new ArrayList();
        baseballTeams.Add("s");
        baseballTeams.Add("r");
        baseballTeams.Add("F");

        foreach (string item in baseballTeams) {
            Console.Write(item + "\n");
        }

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack