I'm practicing C# and wrote the code below excluding the line beginning "Array.Sort....". The output was as expected (i.e. "5,7,2,").
When I included the line "Array.Sort..." I was expecting to get "2,5,7," but got the output "5,5,7,", i.e. the 2 had disappeared and had been replaced by a 5 somehow. Could anyone help explain why (to a beginner)?
namespace ConsoleApplication33
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[3] { 5, 7, 2 };
for (int i = 0; i< numbers.Length; i++)
{
Console.Write(numbers[i] + " , ");
Array.Sort(numbers);
}
Console.ReadKey();
}
}
}
