I have this function :
public static IList<T> myFunction<T>(IList<T> listaCompleta, int numeroPacchetti)
{
return listaCompleta;
}
but if I try to call it with :
IList<SomeObject> listPacchetti = (from SomeObject myso in SomeObjects
select myso).ToList();
listPacchetti = myFunction(listPacchetti, 1);
When I compile it says The type arguments for method 'myFunction<T>(IList<T>, int)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
The fact is that I need to use a IList (or a collection indexes, not a IEnumerable) and I need to pass a generic object to the function (this time a IList<SomeObject>, next time maybe IList<AnotherObject>)
Can I do it? Or what about it? I think that I cannot use IList as type argument…
EDIT – Complete code
I CALL THE FUNCTION FROM ANOTHER CLASS
IList<Packet> listPacchetti = (from Packet pack in Packets
select pack).ToList();
listPacchetti = Utility.Extracts<Packet>(listPacchetti, 6);
CLASS WITH FUNCTION
public class Utility
{
public Utility()
{
}
public static IList<T> Extracts<T>(IList<T> listaCompleta, int numeroPacchetti) // HERE THERE IS THE LINE WITH WARNINGS
{
return listaCompleta;
}
}
Try this;