Skip to main content
1 of 2
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

like @Greg said in his comment - you can make it really short with LINQ and you don't have to check any ranges:

static IEnumerable<T> Remove<T>(this IEnumerable<T> items, int startIndex, int count)
{
    return
        count > 0
        ? items.TakeWhile((x, i) => i < startIndex).Concat(items.Skip(startIndex + count))
        : items.TakeWhile((x, i) => i < (startIndex + count + 1)).Concat(items.Skip(startIndex + 1));
}
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190