Home » Practice Programs

Practice Programs

Program to sort list of names in ascending/descending order.
string[] names = new string[5];
for (int i = 0; i < 5; i++)
{
 names[i] = Console.ReadLine();
 }
Array.Sort(names);  // using system.array
Array.Reverse(names); //if you want list of names to be sorted in descending order
-----------------------------------------------------------------------

Using linq

string[] names = new string[5];
for (int i = 0; i < 5; i++)
{
   names[i] = Console.ReadLine();
 }
var allNames = from a in names
                            orderby a descending
                            select a;