Question

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;
    }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top