【发布时间】:2020-06-13 14:40:24
【问题描述】:
我有一个 Type 变量 -
Type t = typeof(myClass);
如何创建字典 -
Dictionary<String, myClass> 使用类型变量 t?
【问题讨论】:
-
@PavelAnikhouski 是的,确实如此。将我的问题标记为重复
标签: c# .net reflection
我有一个 Type 变量 -
Type t = typeof(myClass);
如何创建字典 -
Dictionary<String, myClass> 使用类型变量 t?
【问题讨论】:
标签: c# .net reflection
您可以将 Activator.CreateInstance 与泛型类型一起使用:
var genType = typeof(Dictionary<,>).MakeGeneric(typeof(string), t);
var dictionary = Activator.CreateInstance(genType);
【讨论】: