I am trying to create a list of a custom type that is set at runtime. How is this possible?
Here is my code:
Type customType = typeof(string); // or someOtherVariable.GetType();
List<customType> ls = new List<customType>(); // Error: The type or namespace name `customType' could not be found
If you want to instantiate a generic list of some reflected type, you’ll have to use Reflection to do so: