help needed in creating runtime objects

hi,
how to create an object whose type is known only at the runtime.
[72 byte] By [singam] at [2007-12-24]
# 1

There are a variety of ways.

//If you have the assembly and type as a string and the assembly might not be loaded yet or you need
//to pass parameters to the constructor
ObjectHandle hdl = Activator.CreateInstance(strAssembly, strType);
object obj = hdl.Unwrap();

//If you have the assembly already
object obj = asm.CreateInstance(strType);

//If you need to pass parameters to the constructor
Type type = Type.GetType(strType);
ConstructorInfo ctor = type.GetConstructor(typeArray);
ctor.Invoke(arguments);

There are a variety of others but these are the most commonly used methods.

Michael Taylor - 9/25/06

TaylorMichaelL at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...