Create Class from Class Name ie "Class1"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?c2lwcHl1Y29ubg==?=

    Create Class from Class Name ie "Class1"

    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
  • Hans van Kruijssen

    #2
    Re: Create Class from Class Name ie "Class1&qu ot;

    sippyuconn wrote:
    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.Creat eInstance(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;

    --
    Hans.

    Comment

    Working...