x


How do i convert a String into a Class reference in C#

I have the String className and i want to convert it to a class reference. what function do i use? for example: new whateverFunction("Class1")(); would be the same as: new Class1();

Is this possible?

more ▼

asked Jan 12 '11 at 12:50 PM

chris 7 gravatar image

chris 7
38 2 3 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You would use the activator class:

System.Activator.CreateInstance(Type.GetType("Class1"));

Documented here:

http://msdn.microsoft.com/en-us/library/wccyzw83.aspx

more ▼

answered Jan 12 '11 at 06:13 PM

Mike 3 gravatar image

Mike 3
30.7k 10 67 255

straight to what i need for now. thanks :)

Jan 19 '12 at 07:25 AM blacksnow
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x430
x352
x276

asked: Jan 12 '11 at 12:50 PM

Seen: 3988 times

Last Updated: Jan 19 '12 at 07:25 AM