Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

like @Greg said in his commentcomment - 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));
}

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));
}

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));
}
Source Link
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));
}