using System.Collections.Generic;
public static void Main()
var numbers=new[]{1,2,3,4,5};
var eg = numbers.Slice(-3,-1);
Console.Write("{0}, ", i);
public static class Extensions
public static IEnumerable<T> Slice<T>(this IEnumerable<T> me, int? start = null, int? end = null)
if (start.HasValue && end.HasValue && start.Value > end.Value)
throw new ArgumentException("starting point must be less than or equal to ending point", "start");
if (start.HasValue && start < 0)
start = me.Count() + start;
if (end.HasValue && end < 0)
return me.Skip(start.Value).Take(end.Value - start.Value);