由于我不能对这篇文章发表任何评论(只发一个答案),我会发一个新问题.
我按照上述帖子中的说明进行操作,但代码产生错误.
代码:
Type t = Type.GetType(className);
Type listType = typeof(List<>).MakeGenericType(t);
IList list = (IList)Activator.CreateInstance(listType);
Run Code Online (Sandbox Code Playgroud)
错误:
使用泛型类型'System.Collections.Generic.IList'需要'1'类型参数
很明显,我不能说IList没有任何类型,所以我想知道上述帖子的答案究竟是如何起作用的.
提前致谢.
你可以,你只需要一个不同的using指令:
using System.Collections;
Run Code Online (Sandbox Code Playgroud)
这样你就可以使用非IList泛型而不是泛型IList<T>.
我相信这是引用答案的精神.