eval a String to have a type

E

Eva

Hi,

My problem is about I have a class name in a string
variable and I need create objects for that class. ¿How am
I able to use the string variable for it?

I have another problem. The class in the first problem is
a form that I'm try to open. The form is created
externally by the user (so isn't in my project) ¿Is
possible to use it without convert the .cs file in a DLL?

Thanks a lot,
Eva.
 
J

Jon Skeet [C# MVP]

Eva said:
My problem is about I have a class name in a string
variable and I need create objects for that class. ¿How am
I able to use the string variable for it?

See Activator.CreateInstance, or if you need to call a specific
constructor, you can use Type.GetType() and then get the specific
constructor and invoke it.
I have another problem. The class in the first problem is
a form that I'm try to open. The form is created
externally by the user (so isn't in my project) ¿Is
possible to use it without convert the .cs file in a DLL?

Yes - have a class library project instead of an application. In this
case you'll need to load the assembly and then use Assembly.GetType
instead of just 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

Top