how to retrieve arraylist items in reverse order


Suppose the arrayList stores data in a particular order, and to retrieve data in a reverse order we use Reverse() method. The below code demonstrates how to display data in a reverse order.



private void Form1_Load(object sender, EventArgs e)
{
    // ArrayList contains Customer names
    ArrayList arrayList = new ArrayList();
    arrayList.Add("Customer1");
    arrayList.Add("Customer2");
    arrayList.Add("Customer3");
    arrayList.Add("Customer4");
    arrayList.Add("Customer5");

	//reversing the array
    arrayList.Reverse();
    string str = string.Empty;
    foreach (string strName in arrayList)
     {
           str += strName + "\n";
     }
     string str = string.Empty;
     for (int i = arrayList.Count - 1; i >= 0; i--)
     {
       str += arrayList[i].ToString() + "\n";
     }





cover image of azure cloud book

Develop Azure Applications

Azure Cloud is gaining popularity and is competing with Amazon Elastic Cloud and Google Cloud for a spot in the billion dollar Cloud computing space.

With this book learn how to use - Table (an Azure Table is different from a SQL Server Table), Queue, Blob storage services, use your local machine to create an Application and a Service, how Azure splits a Table to achieve Load Balancing, Scal