【问题标题】:Is it possible to pass in more than one generically typed parameter to a method?是否可以将多个泛型类型参数传递给一个方法?
【发布时间】:2011-01-16 02:48:45
【问题描述】:

我目前有这个方法头:

public virtual void SetupGrid<T>() where T : class, new()
{

}

我想传入另一个匿名类,我猜是这样的:

public virtual void SetupGrid<T><T2>() where T,T2 : class, new()
{

}

我该怎么做?

【问题讨论】:

    标签: c# .net generics .net-3.5


    【解决方案1】:

    这些被称为泛型。以下是您如何使用其中的几个:

    public virtual void SetupGrid<T, T2>() 
        where T : class, new()
        where T2 : class, new()
    

    this MSDN 页面开始了解介绍和更多信息。

    【讨论】:

    • 西方最快的编译器:)
    【解决方案2】:

    您说的是泛型类型参数,而不是匿名类类型

    是的,这是可能的:

    public virtual void SetupGrid<T,T2>() 
       where T : class, new()
       where T2: class, new()
    {
    
    }
    

    【讨论】:

      【解决方案3】:

      像这样:

              public virtual void SetupGrid<T, T2>() where T : class, new() where T2 : class, new() {
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-05
        • 1970-01-01
        • 1970-01-01
        • 2010-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多