How to code the creation of object when the class is not known?

G

Guest

Normally, to create an object instance based on a specific class, we can do
this.

Dim someObj As Object
someObj = New Class

However,I want to create an object instance based on a variable or
something. For example, I have 3 classes: Class1, Class2, Class3. The
variable dynamicClass can be equal to any of the 3 classes

Dim someObj As Object
someObj = New dynamicClass
 
A

Armin Zingler

Peter said:
Normally, to create an object instance based on a specific class, we
can do this.

Dim someObj As Object
someObj = New Class

However,I want to create an object instance based on a variable or
something. For example, I have 3 classes: Class1, Class2, Class3.
The variable dynamicClass can be equal to any of the 3 classes

Dim someObj As Object
someObj = New dynamicClass


http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx

In particular:
http://msdn2.microsoft.com/en-us/library/k3a58006.aspx
(search for "CreateInstance")


Armin
 
G

Guest

Thanks Armin. I hope I can understand it (reflection) since I'm new to
..net. I hope MS has a webcast to explain it.
 
A

Armin Zingler

Peter said:
Thanks Armin. I hope I can understand it (reflection) since I'm
new to .net. I hope MS has a webcast to explain it.

Do you really need it? I mean, a class name in a variable. What are you
trying to accomplish?


Armin
 
G

Guest

Hi Armin,

One example is that I have 2 windows forms with the same name but in
different path. I want to create an instance of the form but the class may
be one of 2 forms depending on some conditions.
 

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

Top