0

I have a Type variable - Type t = typeof(myClass);

How can I create a Dictionary - Dictionary<String, myClass> using the type variable t?

nischal
  • 35
  • 5

1 Answers1

0

You can use Activator.CreateInstance with a generic-made type:

var genType = typeof(Dictionary<,>).MakeGeneric(typeof(string), t);
var dictionary = Activator.CreateInstance(genType);
Gusman
  • 14,905
  • 2
  • 34
  • 50