Using an Array of Type object

Need help with code to instantiate elements of an array of type object

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2562 Views - Last Post: 15 March 2010 - 04:19 PM Rate Topic: -----

#16 chookscratchings   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 14-March 10

Re: Using an Array of Type object

Posted 15 March 2010 - 04:19 PM

Hi!

Wow, overwhelming response. It's amazing what comes out of one question -- they lead to more.

I managed to get help with instantiating the elements of an array of type Object.

Here it is as a guideline for any of you wishing to do the same.

        Person[] people = new Person[5]; 
        
            
            FT_Teacher ft_teacher = new FT_Teacher("Chan","Jackie",1);
            
            //Instantiate individual classes.
            PT_Teacher pt_teacher = new PT_Teacher("Beng", "Beng",2); 
            pt_teacher.AddSubject(new Subject(10,22,"Science")); 
            pt_teacher.AddSubject(new Subject(12,22,"Maths")); 
            AdminStaff admin = new AdminStaff("Wookie","Amird",3);
            IntStudent int_student  = new IntStudent("Gloop","Augustus",4);  
            LocStudent loc_student =  new LocStudent("Kaye","Danny",5); 

            // Initialise each of the array elements.
            people[0] = ft_teacher; 
            people[1] = pt_teacher; 
            people[2] = admin; 
            people[3] = int_student; 
            people[4] = loc_student; 

            //do the following for each element of the array.
            foreach (Person p in people)
            {
                p.PrintDetails();
            }

This post has been edited by JackOfAllTrades: 15 March 2010 - 09:44 PM
Reason for edit:: Added code tags. PLEASE!!! [code]...PUT YOUR CODE IN HERE!!!...[/code]

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2