![]() | ![]() |
You can use Reverse() and Sort() functions to reverse and sort an array respectively. Look at the following script:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace MyProgram
{
class Program
{
static void Main(string[] args)
{
ArrayList items = new ArrayList();
items.Add(10);
items.Add(50);
items.Add(5);
items.Add(145);
items.Add(30);
––––––––
items.Reverse();
Console.WriteLine(" ====== After reversing =======");
foreach (var element in items)
{
Console.WriteLine(element);
}
items.Sort();
Console.WriteLine("====== After sorting =======");
foreach (var element in items)
{
Console.WriteLine(element);
}
Console.ReadLine();
}
}
}
In the script above, we create an ArrayList “items” with random integers. We then used the Reverse() method to first reverse the list and then we used the Sort() method to sort the list in ascending order. The output of the script above looks like this: