Auto generate instances (VB)

labisem

Member
Joined
May 20, 2003
Messages
10
Auto generate instances

I have a class, Lets say Public Class Employee, and I want to make an instance of this class (Dim emp1 As New Employee) every time the user wish for it, for example with a button click.
Also, after the creation of the object (instance), how can I have access to the particular object (emp1.Age), if I dont know its name?

This may be a simle thing, but I dont know how its done.
 
If you are creating instances on the fly like this you have to store them somewhere before youll be able to go back and use them again. There are a multitude of collection classes in the framework, take a peek at the System.Collections namespace. ArrayList would probably suit you fine.

With Option Strict on you will have to explicitly cast when you get objects out of the collection, to avoid this you can inherit from CollectionBase and make you own strongly-typed collection, but its not essential.

Remembed that objects created at runtime dont have names.
 
Back
Top