返回列表<T>泛型类型

Max*_*ich 3 c# reflection types list

可能重复:
C#通用列表<T>如何获取T的类型?

让我说我有一个List<Stock>给定typeof(List<Stock>)如何确定通用列表的类型是什么?IE:在这种情况下股票?

查看类型信息,我可以看到AssemblyQualifiedName它在某种程度上提供了这一点

System.Collections.Generic.List`1 [[FullQualifiedName.Stock,TestApp,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]],mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089

但我想知道我是否可以实际返回列表的泛型类型?

dig*_*All 6

试试这个:

var innerType = typeof(List<Stock>).GetGenericArguments()[0];
Run Code Online (Sandbox Code Playgroud)

在这种情况下 innerType == typeof(Stock)