Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Auto generate instances

 

I have a class, Let's 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 don't know it's name?

 

This may be a simle thing, but I don't know how it's done.

  • *Gurus*
Posted

If you are creating instances on the fly like this you have to store them somewhere before you'll 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 it's not essential.

 

Remembed that objects created at runtime don't have names.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...