我有一个场景,我得到了 Class name as a string
我只想创建该类的通用 List
。我尝试了以下
Type _type = Type.GetType(className);
List<_type> list = new List<_type>();
但是我收到错误
。我不能把那个 _type 作为列表参数。如果有人知道请帮助我
最佳答案
最接近的:
Type listType = typeof(List<>).MakeGenericType(_type);
IList list = (IList) Activator.CreateInstance(listType);
关于c# - 使用反射的通用列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11509695/