static void Main(string[] args) { //declare array of five School objects School[] schoolArray = new School[5]; int x; //create variable to use as counter for for-loop //prompt user for input on School objects values for (x = 0; x < schoolArray.Length; ++x) { schoolArray[x] = new School(); Console.Write("Enter a school name: "); schoolArray[x].SchoolName = Console.ReadLine(); schoolArray[x].NumStudents = getInt("Enter the school's enrollment: "); } //sort array based on NumStudents property Array.Sort(schoolArray); //display School objects in order of enrollment Console.WriteLine("\nSchools sorted by enrollment: "); for (x = 0; x < schoolArray.Length; ++x) { Console.WriteLine("{0,-20} {1}", schoolArray[x].SchoolName, schoolArray[x].NumStudents); } Console.ReadLine(); //leave command prompt open }
static void Main(string[] args) { //declare array of five School objects School[] schoolArray = new School[5]; int x; //create variable to use as counter for for-loop //prompt user for input on School objects values for (x = 0; x < schoolArray.Length; ++x) { schoolArray[x] = new School(); Console.Write("Enter a school name: "); schoolArray[x].SchoolName = Console.ReadLine(); schoolArray[x].NumStudents = getInt("Enter the school's enrollment: "); } //sort array based on NumStudents property Array.Sort(schoolArray); //display School objects in order of enrollment Console.WriteLine("\nSchools sorted by enrollment: "); for (x = 0; x < schoolArray.Length; ++x) { Console.WriteLine("{0,-20} {1}", schoolArray[x].SchoolName, schoolArray[x].NumStudents); } //declare new int for min enrollment figure int minEnroll; //use getInt method to prompt user for minimum enrollment number and assign to minEnroll minEnroll = getInt("\nEnter a minimum enrollment figure: "); //display School objects meeting or exceeding minEnroll value for (x = 0; x < schoolArray.Length; ++x) { if (schoolArray[x].NumStudents >= minEnroll) { Console.WriteLine("{0,-20} {1}", schoolArray[x].SchoolName, schoolArray[x].NumStudents); } else { } } Console.ReadLine(); //leave command prompt open }