You can use Activator.CreateInstance

Pierre

-----------------------------------------------
Pierre Greborio
[EMAIL PROTECTED]
http://www.pierregreborio.it
-----------------------------------------------



-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of
Henrik Enemark Rasmussen
Sent: Tuesday, May 07, 2002 3:21 PM
To: [EMAIL PROTECTED]
Subject: [DOTNET] HOWTO: Create object from type?


Hello all,

In C#, how can I create an object whoose type is not known until
run-time? I need something similar to MFC's
"RUNTIME_CLASS(CXxx).CreateObject()".

I expect it to look something like this, where the method will then
create an instance of the class and work with it.

public void ShowDialog(Type dialogClass)
{
   if (!dialogClass.IsSubclassOf(typeof(Dialog)))
      throw new ApplicationException("Invalid type");
   .
   .
   .
}

Regards
Henrik

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to