Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取泛型列表的T类型<;T>;对象_C#_List_Generics_Reflection - Fatal编程技术网

C# 获取泛型列表的T类型<;T>;对象

C# 获取泛型列表的T类型<;T>;对象,c#,list,generics,reflection,C#,List,Generics,Reflection,可能重复: 我正在遍历一个类中的PropertyInfo列表。 在这门课上,我对不同的列表感兴趣-例如列表,列表,列表,aso 但我不知道如何获得列表对象的类型。我只是觉得 System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]. 我可以将这些信息分开,然后用这些信息创建一个类型,但我希望有

可能重复:

我正在遍历一个类中的PropertyInfo列表。 在这门课上,我对不同的列表感兴趣-例如
列表
列表
列表
,aso

但我不知道如何获得列表对象的类型。我只是觉得

System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089]].
我可以将这些信息分开,然后用这些信息创建一个类型,但我希望有一个更平滑的方法?

简单:

Type type = list.GetType().GetGenericArguments()[0];
// The first argument will be the `T` inside `List<T>`... so the list type ;)
Type Type=list.GetType().GetGenericArguments()[0];
//第一个参数将是'List'中的'T'。。。所以列表类型;)
或使用一行:

list.GetType().GetGenericArguments()[0]; 
list.GetType().GetGenericArguments()[0];