How To Create An a new unknow Object

  • Thread starter Thread starter Ignacio Machin \( .NET/ C# MVP \)
  • Start date Start date
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Take a look at Activator.CreateInstance

Additionally also look AppDomain.CreateInstance

Cheers,
 
yaniv abo said:
I need somting like this :

object unknowObject= new Customer ();

object obj = new typeof(unknowObject);

how can i do that is c# ?

It's unclear exactly what you want to do. What *do* you know about this
unknown type?
 
Hi,

It goes like this, but my code here will work for you, only if your
Type has a default constructor:

class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
object obj = new ArrayList();
object newObj =
obj.GetType().GetConstructor(Type.EmptyTypes).Invoke(new object[]{});
}
}

Cheers,

Eyal.
 
I need somting like this :

object unknowObject= new Customer ();

object obj = new typeof(unknowObject);

how can i do that is c# ?
 
Back
Top