using System.Collections; class Program { static void Main(string[] args) { ArrayList myList = new ArrayList(); myList.Add(9); myList.Add(2); myList.Add(5); myList.Add(3); myList.Add(7); myList.Sort(); foreach(int number in myList) { Console.WriteLine(number); } } }
using System.Collections; class Program { static void Main(string[] args) { ArrayList myList = new ArrayList(); myList.Add("apple"); myList.Add("banana"); myList.Add("cherry"); myList.Sort(); foreach(string fruit in myList) { Console.WriteLine(fruit); } } }Description: In this code, we create an ArrayList and add some strings to it. We then call the Sort method on the ArrayList instance to sort the elements in ascending order. Finally, we use a foreach loop to print the sorted strings to the console. Package/Library: This method belongs to the .NET framework, specifically the System.Collections namespace. No additional package or library is required.