I need some help with this code. I'm playing with this for a couple of hours and got nothing. So I'm asking for help from you guys.
The Array[b] was always returns out of bounds exception. I don't know why.
{
int[] Array = new int[6];
Array[0] = c;
Array[1] = d;
Array[2] = e;
Array[3] = f;
Array[4] = g;
int a = 0;
int b = 1;
int temp = 0;
for (int counter = 0; counter < Array.Length; counter++)
{
for (int counter2 = 0; counter2 < Array.Length; counter2++)
{
if (Array[a] > Array[b])
{
Console.WriteLine("{0} is Greater Than {1}, Swapping ({0},{1})", Array[a], Array[b]);
temp = Array[a];
Array[a] = Array[b];
Array[b] = temp;
Console.WriteLine("");
}
else
{
Console.WriteLine("{0} is Less Than {1}, Retain Value Position", Array[a], Array[b]);
Console.WriteLine("");
}
a += 1;
b += 1;
}
a = 0;
b = 0;
}
for (int counter = 0; counter < Array.Length; counter++)
{
Console.Write(Array[counter] + " ");
}
Console.WriteLine("Final Position");
return a;
}
Thanks, this is my code i hope any one of you can help me.