public static void Main(string[] args) { Student[] students = { new Student("Bob", 30), new Student("Alex", 22), new Student("Alexey", 22), new Student("Alex", 22), new Student("Max", 18), new Student("Sergey", 20) }; ConsolePrintArray(students, "Created array of students"); Student[] studentsCopy = new Student[students.Length]; Array.Copy(students, studentsCopy, students.Length); sortingUnit.EndOfSorting += PrintSortingEvent; sortingUnit.RunSortInNewThread(students, Student.CompareByName, "Thread CompareByName"); sortingUnit.RunSortInNewThread(studentsCopy, Student.CompareByAge, "Thread CompareByAge"); sortingUnit.SortingUnitThread.Join(); Console.WriteLine(); ConsolePrintArray(students, "Sorted array of students by name"); ConsolePrintArray(studentsCopy, "Sorted array of students by age"); }
private static void Main(string[] args) { Console.WriteLine("Greetings! This is The Sorting Unit demonstration program."); Console.WriteLine(); Person[] people = { new Person { Name = "Masha", Age = 10 }, new Person { Name = "Maria", Age = 11 }, new Person { Name = "Yan", Age = 39 }, new Person { Name = "Oxana", Age = 41 }, new Person { Name = "Sergey", Age = 33 }, new Person { Name = "Tatiana", Age = 66 }, new Person { Name = "Sofia", Age = 27 }, new Person { Name = "Anton", Age = 33 }, new Person { Name = "Andrey", Age = 33 }, new Person { Name = "Dmitriy", Age = 34 }, new Person { Name = "Svetlana", Age = 34 }, new Person { Name = "Artem", Age = 9 }, new Person { Name = "Vasiliy", Age = 32 }, new Person { Name = "Ksenia", Age = 22 } }; Console.WriteLine("Here is an array of Person instances named 'people':"); ConsolePrintPersonArray(people); Console.WriteLine("Let's do a copy of this array and name it 'peopleCopy':"); Person[] peopleCopy = new Person[people.Length]; Array.Copy(people, peopleCopy, people.Length); ConsolePrintPersonArray(peopleCopy); Console.WriteLine("There is a private static instance of SortingUnit class named su."); Console.WriteLine($"Let's add a listener to the End of sorting event for the static SortingUnit instance:{Environment.NewLine}su.EndOfSorting += PrintSortingEvent;"); Console.WriteLine(); su.EndOfSorting += PrintSortingEvent; Console.WriteLine($"Now let's sort original array 'people' by age in new thread using method{Environment.NewLine}RunSortInNewThread(array, compareMethod, threadName)."); Console.WriteLine(); Console.WriteLine($"And let's sort 'peopleCopy' array by name in another new thread using same SortingUnit instance,{Environment.NewLine}but with another thread name."); Console.WriteLine(); su.RunSortInNewThread(people, CompareByAge, "Thread CompareByAge"); su.RunSortInNewThread(peopleCopy, CompareByName, "Thread CompareByName"); su.SortingUnitThread.Join(); Console.WriteLine("Finally, terminate thread with .Join() method."); Console.WriteLine(); Console.WriteLine("And print both original and copy arrays:"); ConsolePrintPersonArray(people); ConsolePrintPersonArray(peopleCopy); }