School.Course.AddStudent C# (CSharp) Method

AddStudent() public method

public AddStudent ( Student newStudent ) : void
newStudent Student
return void
        public void AddStudent(Student newStudent)
        {
            bool studentExists = this.CheckIfStudentExists(newStudent);

            if (studentExists)
            {
                throw new ArgumentException("The student is already enrolled for this course.");
            }

            if (this.Students.Count <= MaxSutentsInCourse)
            {
                this.Students.Add(newStudent);
            }
            else
            {
                throw new ArgumentOutOfRangeException("Class is full!");
            }
        }

Usage Example

 public void AddStudentTwiseTest()
 {
     Course course = new Course("Math");
     Student student = new Student("Gosho", "Ivanov", 12345);
     course.AddStudent(student);
     course.AddStudent(student);
 }
All Usage Examples Of School.Course::AddStudent