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];