Reverse the order of the elements in the entire ArrayList in CSharp

Description

The following code shows how to reverse the order of the elements in the entire ArrayList.

Example


using System;//from   w  ww .j  a v  a  2s .  c  om
using System.Collections;

class MainClass
{
  public static void Main()
  {
    ArrayList myArrayList = new ArrayList();
    myArrayList.Add("A");
    myArrayList.Add("B");
    myArrayList.Add("C");
    myArrayList.Add("D");
    myArrayList.Add("E");

    myArrayList.Reverse();
    
    for (int i = 0; i < myArrayList.Count; i++){
      Console.WriteLine(myArrayList[i]);
    }
  }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary