Grabs a subset of an IEnumerable based on a starting index and position - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

Grabs a subset of an IEnumerable based on a starting index and position

Demo Code

//     Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
using System.Linq;
using System.Collections.Generic;
using System;//  ww  w.  ja  v a  2s  .  c  o m

public class Main{
        /// <summary>
        /// Grabs a subset of an IEnumerable based on a starting index and position
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">The array of items to slice</param>
        /// <param name="startIndex">The starting position to begin the slice</param>
        /// <param name="count">The number of items to take</param>
        /// <returns>A slice of size <see cref="count"/> beginning from position <see cref="startIndex"/> in <see cref="items"/>.</returns>
        internal static IEnumerable<T> Slice<T>(this IEnumerable<T> items, int startIndex, int count)
        {
            return items.Skip(startIndex).Take(count);
        }
}

Related Tutorials