Esempio n. 1
0
        public void AddStudent(Student student)
        {
            if (student == null)
            {
                throw new ArgumentNullException("student", "Student cannot be null.");
            }

            if (this.students.Contains(student))
            {
                throw new InvalidOperationException("This student has been already added.");
            }

            if (student.GetType() != typeof(Student))
            {
                throw new ArgumentException("You cannot add non student objects to students");
            }

            if (this.students.Any(st => st.Id == student.Id))
            {
                throw new ArgumentException("There is already a student with the same ID.");
            }

            this.students.Add(student);
        }
Esempio n. 2
0
        public void RemoveStudent(Student student)
        {
            if (student == null)
            {
                throw new ArgumentNullException("student", "Removing student requires student object as argument");
            }

            if (student.GetType() != typeof(Student))
            {
                throw new ArgumentException("You cannot remove non student objects from students");
            }

            if (!this.students.Contains(student))
            {
                throw new InvalidOperationException("There is no such student.");
            }

            this.students.Remove(student);
        }