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.
 

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

Back
Top