I have code like this:
Type typPrecise = MostPrecise(typeof(int), typeof(double));//Evaluates to double
var varGeneric = typeof(Number<>);
var varSpecific = varGeneric.MakeGenericType(typPrecise);
dynamic nmNumber = Activator.CreateInstance(varSpecific);
The nmNumber is of dynamic type and essentially produces a Generic Number. How do I then specify the number of items in Number.
I basically want to accomplish this but by using the dynamic code above:
Number<typPrecise> whatever = new Number<typPrecise>(10);
An answer using 4.0 concepts is welcome.
Call the overload of Activator.CreateInstance that accepts constructor arguments:
Incidentally note that the
List<T>(int)constructor sets the initial capacity of the List, not the initial number of items (Count). The initial Count is always 0.