0

I classes called classA,ClassB,ClassC. There is a string called className which holds the name of the class.. Instead of using bunch of If else statements, Is there any method to create new class like

new className()

Abhinav Konda
  • 225
  • 1
  • 11
  • [There is](http://msdn.microsoft.com/en-gb/library/d133hta4.aspx).. but what are you trying to do instead? there may be better alternatives to your approach – Sayse Jun 20 '14 at 08:40
  • I have a dictionary of key and class names. Based on the value of key name I want to return the class objects to baseclass variable – Abhinav Konda Jun 20 '14 at 08:43
  • @AbhinavKonda - Im struggling to ever find a reason you'd want to do that, what are you trying to achieve? – Sayse Jun 20 '14 at 08:45
  • What is the other alternative? – Abhinav Konda Jun 20 '14 at 08:50

1 Answers1

1

You can use Activator class for the same

eg.

        Activator.CreateInstance<className>();

or

        Activator.CreateInstance(typeof(className));
pushpraj
  • 13,458
  • 3
  • 33
  • 50