public void On_Main() { SortArrayDelegate sortM1 = SortStudents; Student[] students = { new Student { FirstName = "Ivan", Score = 150 }, new Student { FirstName = "Igor", Score = 140 }, new Student { FirstName = "Vasyl", Score = 166 }, new Student { FirstName = "Mykola", Score = 171 }, new Student { FirstName = "Stepan", Score = 129 } }; PrintArray(students); SortSth(students, sortM1); Console.WriteLine("---"); PrintArray(students); }
public void SortSth(object[] sortArray, SortArrayDelegate sortArrayDelegate) { for (int i = 0; i < sortArray.Length; i++) { for (int j = 0; j < sortArray.Length; j++) { if (sortArrayDelegate(sortArray[i], sortArray[j])) { var temp = sortArray[i]; sortArray[i] = sortArray[j]; sortArray[j] = temp; } } } }