Create Class from Class Name ie "Class1"

  • Thread starter Thread starter sippyuconn
  • Start date Start date
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
 
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;
 
Back
Top