public void RemoveCourse(Course c) { if (c == this.courses[this.CourseCount - 1]) { this.courses[this.CourseCount--] = null; c.RemoveStudent(this); return; } bool notFound = true; for (int i = 0; i < this.CourseCount - 1; ++i) { if (c == this.courses[i] && notFound) { this.courses[i] = null; this.CourseCount--; c.RemoveStudent(this); notFound = false; } if (!notFound) { this.courses[i] = this.courses[i + 1]; } } }
static void Main(string[] args) { var s0 = new Student("Naimul 0", "154", 3.50F); var s1 = new Student("Naimul 1", "19", 3.61F); var s2 = new Student("naimul 10", "22", 3.62F); var c0 = new Course("001", "Web tech"); var c1 = new Course("002", "DLC"); var c2 = new Course("003", "OOP 2"); c0.AddStudent(s1, s2); c0.PrintStudent(); c0.RemoveStudent(s0); Console.WriteLine("******After student removed*****"); s0.PrintCourse(); c0.PrintStudent(); Console.WriteLine(); s2.AddCourse(c0, c1, c2); s2.PrintCourse(); s2.RemoveCourse(c1); Console.WriteLine("##### After Remove A Course#####"); s2.PrintCourse(); c1.PrintStudent(); }