There are many ways to perform sofisticated sorting in C# and there are many webpages covering that subject. This page will show how to perform the most basic type of sorting in C#. That is sorting an Array or ArrayList in ascending and descending order.
C# sorting examples Let’s look at some basic sorting examples:
string myStringArray = new string; myStringArray = "b"; myStringArray = "a"; myStringArray = "c"; // will sort in ascending order Array.Sort(myStringArray); // reverses the order so now descending Array.Reverse(myStringArray); ArrayList myArrayList = new ArrayList(); myArrayList.Add("b"); myArrayList.Add("c"); myArrayList.Add("a"); // will sort in ascending order myArrayList.Sort(); // reverses the order so now descending myArrayList.Reverse();