简体   繁体   中英

Parametric polymorphism in c#?

I am trying to create a parametric polmorphism function in c#:

I want to have T be the type variable. But I am getting error about class T is not found.

Does anyone know how to fix this?

Thanks.

    public List<T> getX(SPListItemCollection itemCollection, List<T> itemList, Report RO, WebpartSettings WPS)
    {
        foreach (T item in itemCollection)
        {
            if (have_permissions_for_item(WPS.EDIT_MODE, item, RO))
            {
                itemList.Add(item);
            }
        }
        return itemList;
    }

Change

public List<T> getX(SPListItemCollection itemCollection, List<T> itemList, Report RO, WebpartSettings WPS)

to

public List<T> getX<T>(SPListItemCollection itemCollection, List<T> itemList, Report RO, WebpartSettings WPS)

Have a closer look at how Generic Methods (C# Programming Guide) does it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM