How to create extension method for IList

I’m trying to create an extension method for a generic List using this code:

public static int WrapIndex(this IList<T> list, int counter)

but I’m getting this error:

The type or namespace name `T’ could
not be found. Are you missing a using
directive or an assembly reference?

Any help is much appreciated - thanks!

You need to define T in the extension method declaration like this:

public static int WrapIndex<T>(this IList<T> list, int counter)

Then you can use the method like this:

List<int> myList = new List<int>();
int myNumber = myList.WrapIndex(4);

Hope that helps.