ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Slice of IEnumerable

Returns count elements, beginning from the specified

Source

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 }

Author: Sergei Bogachev

Submitted on: 25 aug. 2015

Language: C#

Type: System.Collections.Generic.IEnumerable<T>

Views: 7029