在给出Collection <T>对象的情况下查找"T"

Nil*_*oCK 3 c# reflection types

代码

BindingList<String> list = new BindingList<String>();
Console.WriteLine("Type: " + list.GetType());
Run Code Online (Sandbox Code Playgroud)

产生输出

Type: System.ComponentModel.BindingList`1[System.String]
Run Code Online (Sandbox Code Playgroud)

但我想要的只是'System.String'.

这个问题与使用反射的现有问题Get type基本相反.

D S*_*ley 8

你可以使用Type.GetGenericArguments:

list.GetType().GetGenericArguments()[0];
Run Code Online (Sandbox Code Playgroud)