【问题标题】:Finding "T" given a Collection<T> object在给定 Collection<T> 对象的情况下查找“T”
【发布时间】:2014-02-14 02:41:31
【问题描述】:

代码

BindingList<String> list = new BindingList<String>();
Console.WriteLine("Type: " + list.GetType());

产生输出

Type: System.ComponentModel.BindingList`1[System.String]

但我想要的只是“System.String”。

这个问题本质上与现有问题Get type using reflection相反。

【问题讨论】:

  • 嗯,它不是一个字符串。你得到了类型,你想知道泛型参数。

标签: c# reflection types


【解决方案1】:

你可以使用Type.GetGenericArguments:

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

【讨论】:

    猜你喜欢
    • 2017-02-26
    • 2014-10-15
    • 2012-05-26
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多