I have class like this:
public ClassA<T> where T : class{
...
}
Now I need to to create an object of ClassA in the constructor of ClassB:
public ClassB{
public ClassA<?> objA;
public ClassB(string TypeInfo){
objA = new ClassA<?>(); // Suppose TypeInfo = 'ClassC', and the '?'
// Should be derived from TypeInfo
}
...
}
I don't know what to replace '?' for, since the type can only be known at runtime... any ideas?
ClassAneeds to declarewhere T : class, new()if you want to use the default constructor. Also, @ArturMustafin is mistaken.objecttypeClassBgeneric, and use ILGeberator() for the generic ClassB to instantiate of construction of genericClassAthat at the run-time