Create Class from Class Name ie "Class1"

S

sippyuconn

Hi

This is from within an EXE that actaully contains the class - No external
assembly

I would do

Class1 myClass = new Class1();

Now I want

string sClass = "Class1";

How do I create an Instance of Class1 from sClass ???

Thanks
 
H

Hans van Kruijssen

sippyuconn said:
Hi

This is from within an EXE that actaully contains the class - No
external assembly

I would do

Class1 myClass = new Class1();

Now I want

string sClass = "Class1";

How do I create an Instance of Class1 from sClass ???

Thanks

Use Activator.CreateInstance(Type.GetType(sClass));
If the class is in an external dll you need to use the fully qualified
name.

You can obtain the fully qualified name of a class using:
typeof(Class1).FullName;
 

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