Class and subClass

Maybe is a silly question but… not for me.

We have a class: Person
And several subclasses: Student, Teacher, ServicePerson
Person has its properties and methods that are inherit by subclasses.
For example Person.fullName()

Each subclass has its properties and methods.
For example:
Student.register()
Teacher.teach()
ServicePersonal.clean()

We have an array with all Persons and want to know witch students are already registered:

  For each p as Person in Persons
  if p isa Student then
    dim s as string = p.FullName
    
    if p.register then // don't work because p is a Person 
      // How do I convert p to a Student? To access the Student methods?
      
    end if
  end if
Next
  

Why not just having an array called Students, holding all Student objects.

What you are looking for is type casting:

For each p as Person in Persons if p isa Student then dim s as string = p.FullName if Student(p).register then // whatever end if end if Next

Thanks Ulrich I was looking for this kind of casting and wasn’t able to found any documentation on it.

Thans Joost, but I want to have all persons in and array. Not an array for each subclass.