Use string value to create new instance
Posted
by Brian David Berman
on Stack Overflow
See other posts from Stack Overflow
or by Brian David Berman
Published on 2010-05-06T03:23:41Z
Indexed on
2010/05/06
3:28 UTC
Read the original article
Hit count: 290
I have a few classes: SomeClass1, SomeClass2.
How can I create a new instance of one of these classes by using the class name from a string?
Normally, I would do:
var someClass1 = new SomeClass1();
How can I create this instance from the following:
var className = "SomeClass1";
I am assuming I should use Type.GetType() or something but I can't figure it out.
Thanks.
© Stack Overflow or respective owner