Not getting items from the list
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Not getting items from the list

  1. #1
    Join Date
    Jan 2012
    Posts
    39

    Not getting items from the list

    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");
    
            }

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,553

    Re: Not getting items from the list

    I note your earlier post as well re same topic. If you care to post the complete code that complies and runs and produces the problem I'll have a look at it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center