CSharp examples for System.Collections.Generic:IList
Subset from IList
using System.Linq; using System.Collections.Generic; public class Main{ public static IList<T> Subset<T>(this IList<T> obj, int offset, int count) {//from ww w .j a v a 2 s . c om //Guard against bad input offset.NotLessThan(0); count.NotLessThan(0); (obj.Count - (offset + count)).NotNegative(); var resultantList = new List<T>(); for (var i = offset; i < offset + count; i++) { resultantList.Add(obj[i]); } return resultantList; } public static IEnumerable<T> Subset<T>(this IEnumerable<T> obj, int offset, int count) { return Subset(obj.ToList(), offset, count); } }