是否可以实现如下代码?我知道这行不通,但我想知道是否有解决方法?
Type k = typeof(double);
List<k> lst = new List<k>();
最佳答案
是的,有:
var genericListType = typeof(List<>);
var specificListType = genericListType.MakeGenericType(typeof(double));
var list = Activator.CreateInstance(specificListType);
关于c# - 使用包含 Type 的变量创建 Generic<T> 类型实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2078914/