int[] CarInTime=new int[]{45,67,566,666,555,23}; int temp; for (int j = 0; j < CarInTime.Length - 1;j++ ) { for (int i = 0; i < CarInTime.Length -j - 1; i++) { if (CarInTime[i] > CarInTime[i + 1]) { temp = CarInTime[i]; CarInTime[i] = CarInTime[i + 1]; CarInTime[i + 1] = temp; } } } for (int k = 0; k < CarInTime.Length; k++) { MessageBox.Show(Convert.ToString(CarInTime[k ])); }