//Takes in all students and checks if they are on the roster of the instance object //if the ZID is found int the roster it will print the student using the .ToString() override. public string PrintRoster(BindingList <Student> students) { var builder = new StringBuilder(); if (students == null) { throw new ArgumentNullException("students cannot be null."); } var courseInfo = string.Format("Course: {0} {1}-{2} ({3}/{4})", DepartmentCode, CourseNumber, SectionNumber, EnrolledCount, MaximumCapacity); builder.Append(courseInfo); builder.Append(Environment.NewLine); builder.Append("-------------------------------------------------------------------"); builder.Append(Environment.NewLine); if (!EnrolledStudents.Any()) { builder.Append("There are no students currently enrolled in this course."); } else { foreach (var student in students) { if (EnrolledStudents.Contains(student.ZId)) { var studentInfo = string.Format("{0}\t{1}, {2}\t{3}", student.ZId, student.LastName, student.FirstName, student.Major); builder.Append(studentInfo); builder.Append(Environment.NewLine); } } } return(builder.ToString()); }
//Takes in all students and checks if they are on the roster of the instance object //if the ZID is found int the roster it will print the student using the .ToString() override. public void PrintRoster(List <Student> students) { if (students == null) { throw new ArgumentNullException("students cannot be null."); } Console.WriteLine("\nCourse: {0} {1}-{2} ({3}/{4})", DepartmentCode, CourseNumber, SectionNumber, EnrolledCount, MaximumCapacity); Console.WriteLine("-------------------------------------------------------------------"); if (!EnrolledStudents.Any()) { Console.WriteLine("There are no students currently enrolled in this course."); } else { foreach (var student in students) { if (EnrolledStudents.Contains(student.ZId)) { Console.WriteLine("{0} {1}, {2} {3}", student.ZId, student.LastName, student.FirstName, student.Major); } } } }