Search code examples
c#asp.netienumerable

Paging through an IEnumerable


I have an IEnumerable object (IEnumerable<Class>) and I would like to retrieve a specified line from the object. So if I'm on page two I would like to select row two from the IEnumerable object and then pass it on to another class etc.

I'm a bit stuck at the moment, any ideas?


Solution

  • Look at the functions .Take() and .Skip(). I normally do something like this:

    IEnumerable<object> GetPage(IEnumerable<object> input, int page, int pagesize)
    {
         return input.Skip(page*pagesize).Take(pagesize);
    }