This uses a heap sort. It might be take some time for you to figure out how heap sort works but its worth it. If you can, read about it and then see how it is implemented here.
static void Main(string[] args)
{
string[,] name = new string[10,2];
for (int i = 0; i <= 9; i++)
{
Console.Write("Please enter a name ");
name[i,0] = Console.ReadLine();
Console.Write("Please enter a rank ");
name[i,1] = Console.ReadLine();
}
Console.WriteLine(name.Length.ToString());
sortArray(name, name.Length/2 - 1);
for (int i = 0; i <= 9; i++)
{
Console.WriteLine(name[i,0] + " " + name[i, 1]);
}
Console.Read();
}
public static void sortArray(string[,] a, int x)
{
int i;
string temp;
string strTemp;
for (i = (x / 2) - 1; i >= 0; i--)
{
siftDown(a, i, x);
}
for (i = x - 1; i >= 1; i--)
{
//swapping values at indices 0 & 1
temp = a[0, 1];
a[0, 1] = a[i, 1];
a[i, 1] = temp;
strTemp = a[0, 0];
a[0, 0] = a[i, 0];
a[i, 0] = strTemp;
siftDown(a, 0, i - 1);
}
}
/// <summary>
/// This method is used my sortArray()
/// </summary>
/// <param name="a"></param>
/// <param name="root"></param>
/// <param name="bottom"></param>
public static void siftDown(string[,] a, int root, int bottom)
{
bool done = false;
int maxChild;
string temp;
string strTemp;
while ((root * 2 <= bottom) && (!done))
{
if (root * 2 == bottom)
maxChild = root * 2;
else if (Convert.ToDouble(a[root * 2, 1]) < Convert.ToDouble(a[root * 2 + 1, 1]))
maxChild = root * 2;
else
maxChild = root * 2 + 1;
if (Convert.ToDouble(a[root, 1]) > Convert.ToDouble(a[maxChild, 1]))
{
//swapping values at indices 0 & 1
temp = a[root, 1];
a[root, 1] = a[maxChild, 1];
a[maxChild, 1] = temp;
strTemp = a[root, 0];
a[root, 0] = a[maxChild, 0];
a[maxChild, 0] = strTemp;
root = maxChild;
}
else
{
done = true;
}
}
}