I have 2 lists one for JuniorStudents and one for SeniorStudents. In the JuniorStudents I have a method for promoting a juniorstudent to a seniorStudent. I am first deleting the juniorstudent and then putting it into the seniorstudent list. However when I try to view the student when calling the method viewStudents I am not getting the student. Any ideas why this is so. Here is the code:
Code:public class SeniorStudentsClass { public List<Student> studlist = new List<Student>(); public void ViewStudents() { for (int i = 0; i < studlist.Count; i++) { Console.Write(studlist[i].Id + "\t"); Console.Write(studlist[i].Year + "\t"); Console.Write(studlist[i].Name + "\t"); Console.Write(studlist[i].Surname + "\t"); Console.Write(studlist[i].DOB + "\t"); Console.Write(studlist[i].Addr); Console.WriteLine(); } public class JuniorStudentsClass { public List<Student> mystudent = new List<Student>(); SeniorStudentsClass sc = new SeniorStudentsClass(); public void PromoteStudents(int index) { SearchItem(index); Console.WriteLine("current record:"); Console.WriteLine("id is:" + mystudent[index].Id); Console.WriteLine("year is:" + mystudent[index].Year); Console.WriteLine("name is:" + mystudent[index].Name); Console.WriteLine("surname is:" + mystudent[index].Surname); Console.WriteLine("dob is:" + mystudent[index].DOB); Console.WriteLine("address is:" + mystudent[index].Addr); Console.WriteLine("year is:"+mystudent[index].Year); if (((mystudent[index].Year== 7)) || ((mystudent[index].Year == 8))) { var student = mystudent[index]; mystudent.RemoveAt(index); sc.studlist.Add(student); Console.WriteLine("student promoted to senior student"); }


Reply With Quote

Bookmarks