Class Instantiation by name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do i instantiate a class if I get the name of the class at runtime ?
I am looking for something like class.forname("classABC") in Java .

TIA
Mandar
 
=?Utf-8?B?TWFuZGFy?= said:
How do i instantiate a class if I get the name of the class at runtime ?
I am looking for something like class.forname("classABC") in Java .

Well, Type.GetType is roughly the equivalent of Class.forName, but
Activator.CreateInstance is roughly the equivalent of
Class.newInstance.

Note that in order to get a Type object for a type in an assembly other
than either the calling one or mscorlb, you need to either load the
assembly yourself and use Assembly.GetType, or include the full name of
the type including assembly information in the call to Type.GetType.
 
Back
Top