我对我正在寻找的术语不太确定但是......
//here's a new list:
List<string> AList = new List<string>();
Run Code Online (Sandbox Code Playgroud)
现在我如何从"AList"中获得"字符串"的类型?
/*I cant just ".GetType()" a value within the list since there aren't any values
and "AList.GetType()" would give me the type of "List<string>".*/
Run Code Online (Sandbox Code Playgroud)
这将为您提供列表的类型
List<string> AList = new List<string>();
Type type = AList.GetType().GetGenericArguments()[0];
Console.WriteLine(type.Name);
Run Code Online (Sandbox Code Playgroud)
产量
String
Run Code Online (Sandbox Code Playgroud)
其他资源
返回Type对象的数组,表示闭合泛型类型的类型参数或泛型类型定义的类型参数.
返回
Type[]
一个Type对象数组,表示泛型类型的类型参数.如果当前类型不是泛型类型,则返回空数组.