Slice of IEnumerable

using System.Linq;

...

public static IEnumerable<T> Slice<T>(this IEnumerable<T> collection, int start, int count)
{
    if (collection == null)
        throw new ArgumentNullException("collection");

    return collection.Skip(start).Take(count);
}
Example:
int[] fake = {1, 2, 3, 4, 5, 6, 7, 8, 9 };
var seq2 = Slice(fake, 3, 2).ToArray(); // returns { 4, 5 }

        

Description

Returns count elements, beginning from the specified

Details

Double click on the code to select all.

 

;