Use the built-in class System.Collections.Generic.List<T>. If you want to remove items, do not make your life harder than it should be.
list.RemoveAt(2);
Keep in mind that the actual code for this is not so complicated. The point is, why not use the built-in classes?
public void RemoveAt(int index)
{
if (index >= this._size)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
this._size--;
if (index < this._size)
{
Array.Copy(this._items, index + 1, this._items, index, this._size - index);
}
this._items[this._size] = default(T);
this._version++;
}
source
share