int[] array = { 5,4,3,1,2};//1 4 3 2 5//1 2 3 4 5 for (int i = 0; i < array.Length; i++) { int min = array[i]; int index = i; for (int j = i+1; j < array.Length ; j++) { if (array[j] < min) { index = j; min = array[j]; } } int temp; temp = array[i]; array[i] = min; array[index] = temp; }