static void Main(string[] args) { int[] arr = {4, 5, 6, 1 }; foreach (var item in arr) { Console.Write(item+" "); } for (int j = 0; j < arr.Length-1; j++) { for (int i = 0; i < arr.Length - 1-j; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; } } } Console.WriteLine(); foreach (var item in arr) { Console.Write(item + " "); } }