Try:
List<string> options = new List<string>();
List<string> lastOptions = options.Skip(0).Take(5).ToList();
skip is used to show how to skip x elements (tnx drch)
You could create something like this: (extension method)
public static class SpliceExtension
{
public static List<T> Splice<T>(this List<T> list, int offset, int count)
{
return list.Skip(offset).Take(count).ToList();
}
}
But this will only be available to Lists.
You could also use it on IEnumerable<>
public static class SpliceExtension
{
public static IEnumerable<T> Splice<T>(this IEnumerable<T> list, int offset, int count)
{
return list.Skip(offset).Take(count);
}
}
This way the List isn't iterated completely.
use it like:
List<string> lastOptions = options.Splice(1, 5).ToList();
I like this way more, because it can be used on several linq queries.