School.Course.RemoveStudent C# (CSharp) Method

RemoveStudent() public method

public RemoveStudent ( Student student ) : void
student Student
return void
        public void RemoveStudent(Student student)
        {
            bool studentFound = this.CheckIfStudentExists(student);

            if (!studentFound)
            {
                throw new ArgumentException("There is no such student in the course.");
            }

            this.Students.Remove(student);
        }

Usage Example

Beispiel #1
0
        private static void Main()
        {
            try
            {
                Student pesho = new Student("Pesho Georgiev");
                Student gosho = new Student("Gosho Ivanov");
                Student misho = new Student("Misho Cekov");
                Student sasho = new Student("Sasho Kostov");

                Course telerikAcademy = new Course("Telerik Academy");
                Course webProgramming = new Course("Web Programming");

                webProgramming.AddStudent(sasho);

                telerikAcademy.AddStudent(pesho);
                telerikAcademy.AddStudent(gosho);
                telerikAcademy.AddStudent(misho);

                telerikAcademy.RemoveStudent(gosho);
                Console.WriteLine(gosho.ToString() + " was removed from course.");

                Console.WriteLine("Courses:");
                Console.WriteLine(telerikAcademy);

                School freeSchool = new School("School of Computer Sciences");
                freeSchool.AddCourse(webProgramming);
                freeSchool.AddCourse(telerikAcademy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
All Usage Examples Of School.Course::RemoveStudent