I have a Type
variable -
Type t = typeof(myClass);
How can I create a Dictionary -
Dictionary<String, myClass>
using the type variable t?
I have a Type
variable -
Type t = typeof(myClass);
How can I create a Dictionary -
Dictionary<String, myClass>
using the type variable t?
You can use Activator.CreateInstance with a generic-made type:
var genType = typeof(Dictionary<,>).MakeGeneric(typeof(string), t);
var dictionary = Activator.CreateInstance(genType);