Create object with dynamically generated name ?

  • Thread starter Thread starter vertigo
  • Start date Start date
V

vertigo

Hello

I need to create some objects durring program execution - but it's names
are dynamically generated (depends on parameters). How can i do it ?

Thanx
Michal
 
vertigo said:
Hello

I need to create some objects durring program execution - but it's names
are dynamically generated (depends on parameters). How can i do it ?

What kind of objects? Not all objects have names, after all. If you're
talking about, say, Windows Forms controls, then yes they have a .Name
property, but there don't appear to be any undue complications there.
If however you are trying to say that you want to dynamically generate
object *variables'* names, then we would find ourselves in a state of
confusion.
 
Michal,

You will want to take a look at the static CreateInstance method on the
Activator class. It will allow you to create instances from a Type, which
you can get from the static GetType method on the Type class (assuming you
have a string indicating which type you want).

Hope this helps.
 
You can use several ways, depending of what you have:

Activator.CreateInstance
AppDomain.CreateInstance

Check MSDN to see which one is more suitable to your needs

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top