动态列表< T>类型类型、动态、列表、LT

由网友(你那么骄傲不如脱光了炫耀)分享简介:是否有可能创建一个新的名单,其中,T> ,其中T为动态设置在运行时Is it possible to create a new List where the T is dynamically set at runtime?干杯推荐答案这是可能的,但不一定是有用的,因为你不能真正使用它的编译code是...

是否有可能创建一个新的名单,其中,T> ,其中T为动态设置在运行时

Is it possible to create a new List<T> where the T is dynamically set at runtime?

干杯

推荐答案

这是可能的,但不一定是有用的,因为你不能真正使用它的编译code是强类型。创造code会

It's possible, but not necessarily useful, since you couldn't actually use it from compiled code as strongly typed. The creation code would be

    Type myType;
    Type listType = typeof(List<>).MakeGenericType(myType);
    IList myList = (IList)Activator.CreateInstance(listType);
阅读全文

相关推荐

最新文章