非泛型类中的泛型方法? [英] Generic method in a non-generic class?

查看:154
本文介绍了非泛型类中的泛型方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信我以前做过这个,但找不到任何例子! Grrr ...

例如,我想将 IList< T> 转换为 BindingList< T>

  public class ListHelper 
{
公共静态BindingList< T> ToBindingList(IList< T>数据)
{
BindingList< T> output = new BindingList< T>();

foreach(数据中的T项)
output.Add(item);

返回输出;


$ / code $ / pre

解决方案

  ToBindingList< T> (...)






  public class ListHelper 
{
public static BindingList< T> ToBindingList< T>(IList< T>数据)
{
BindingList< T> output = new BindingList< T>();

foreach(数据中的T项)
{
output.Add(item);
}

返回输出;
}
}


I'm sure I've done this before, but can't find any example of it! Grrr...

For example, I want to convert an IList<T> into a BindingList<T>:

public class ListHelper
{
    public static BindingList<T> ToBindingList(IList<T> data)
    {
        BindingList<T> output = new BindingList<T>();

        foreach (T item in data)
            output.Add(item);

        return output;
    }
}

解决方案

ToBindingList <T> (...)


public class ListHelper
{
    public static BindingList<T> ToBindingList<T>(IList<T> data)
    {
        BindingList<T> output = new BindingList<T>();

        foreach (T item in data)
        {
            output.Add(item);
        }

        return output;
    }
}

这篇关于非泛型类中的泛型方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆