在运行时指定generics集合类型参数

我有:

class Car {..} class Other{ List GetAll(){..} } 

我想要做:

 Type t = typeof(Car); List Cars = GetAll(); 

我怎样才能做到这一点?

我想从我在运行时使用reflection发现的类型的数据库中返回一个generics集合。

 Type generic = typeof(List<>); Type specific = generic.MakeGenericType(typeof(int)); ConstructorInfo ci = specific.GetConstructor(Type.EmptyTypes); object o = ci.Invoke(new object[] { }); 

你可以使用reflection:

 Type t = typeof(Car); System.Type genericType= generic.MakeGenericType(new System.Type[] { t}); Activator.CreateInstance(genericType, args);