I’m looking for the Skip method of IEnumerable interface.
IList public IEnumerable interface, so I thought I was able to access that method.
Anyway the following code fails to compile on Mono:
private static void SkipFirst(IList<float> list)
{
IList<float> skippedFirst = list.Skip(1);
}
Here’s the error:
error CS1061: Type
System.Collections.Generic.IList<float>' does notSkip’ and no extension method
contain a definition forSkip' of typeSystem.Collections.Generic.IList’ could be found (are you
missing a using directive or an assembly reference?)
What am I doing wrong? How can I access that method from an IList interface?
Skipis an extension method, so it is not actually a method of any of the collection classes. Instead it is defined by Linq. You need to add a reference to Linq:using System.Linq;list.Skip(1)is just syntactical sugar, it is actually converted toEnumerable.Skip(list, 1)Also,
SkipreturnsIEnumerable<T>which means you need to use eitheror