C# | Remove element at specified index of Collection<T>
Collection<T>.RemoveAt(Int32) is used to remove the element at the specified index of the Collection<T>.
public void RemoveAt (int index);
Here, index is the zero-based index of the element to remove.
Exception: This method will give ArgumentOutOfRangeException if the index is less than zero OR index is equal to or greater than Count.
Below given are some examples to understand the implementation in a better way:
Count : 5 A B C D E Count : 4 A B D E
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Note: This method is an O(n) operation, where n is Count.
My Personal Notes arrow_drop_up
Please Login to comment...