E
Einar Værnes
Hi.
I am trying to programatically decide which type a new object should have,
but the typeof-function is apparently not the answer, as the following code
will not compile.
class AbstractClass:Object { }
class DerivedClass1 : AbstractClass { }
class DerivedClass2 : AbstractClass { }
static class Program
{
static void Main()
{
AbstractClass a,b,c;
a = new DerivedClass1();
b = new DerivedClass2();
if (some_condition)
c = new (typeof(a))();
else
c = new (typeof(b))();
}
}
How can implement this?
Best regards
Einar Værnes
I am trying to programatically decide which type a new object should have,
but the typeof-function is apparently not the answer, as the following code
will not compile.
class AbstractClass:Object { }
class DerivedClass1 : AbstractClass { }
class DerivedClass2 : AbstractClass { }
static class Program
{
static void Main()
{
AbstractClass a,b,c;
a = new DerivedClass1();
b = new DerivedClass2();
if (some_condition)
c = new (typeof(a))();
else
c = new (typeof(b))();
}
}
How can implement this?
Best regards
Einar Værnes