相关疑难解决方法(0)

将实例化的System.Type作为泛型类的类型参数传递

标题有点模糊.我想知道的是,如果可能的话:

string typeName = <read type name from somwhere>;
Type myType = Type.GetType(typeName);

MyGenericClass<myType> myGenericClass = new MyGenericClass<myType>();
Run Code Online (Sandbox Code Playgroud)

显然,MyGenericClass被描述为:

public class MyGenericClass<T>
Run Code Online (Sandbox Code Playgroud)

现在,编译器抱怨'找不到类型或命名空间'myType'."必须有办法做到这一点.

.net c# generics

174
推荐指数
2
解决办法
8万
查看次数

标签 统计

.net ×1

c# ×1

generics ×1