By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Class Instantiation by name

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
=?Utf-8?B?TWFuZGFy?= <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2

P: n/a
=?Utf-8?B?TWFuZGFy?= <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.