List<T>.RemoveAt (Int32) Method is used to remove the element at the specified index of the List<T>.
Properties of List:
- It is different from the arrays. A list can be resized dynamically but arrays cannot.
- List class can accept null as a valid value for reference types and it also allows duplicate elements.
- If the Count becomes equals to Capacity then the capacity of the List increases automatically by reallocating the internal array. The existing elements will be copied to the new array before the addition of the new element.
public void RemoveAt (int index);
index: It is the zero-based starting index of the element which is to be removed.
count: It is the number of the elements which is to be removed.
Exceptions: This method will give ArgumentOutOfRangeException if the index is less than 0 or equal to or greater than Count.
Below programs illustrate the use of List<T>.RemoveAt (Int32) Method:
Elements Present in List: At Position 0: 17 At Position 1: 19 At Position 2: 21 At Position 3: 9 At Position 4: 75 At Position 5: 19 At Position 6: 73 Removing the element at index 3 At Position 0: 17 At Position 1: 19 At Position 2: 21 At Position 3: 75 At Position 4: 19 At Position 5: 73
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Elements Present in List: At Position 0: 17 At Position 1: 19 At Position 2: 21 At Position 3: 9 At Position 4: 75 At Position 5: 19 At Position 6: 73 Removing the element at index 3
- C# | Remove the element at the specified index of the ArrayList
- C# | Remove element at specified index of Collection<T>
- C# | Gets or Sets the element at the specified index in the List
- C# | Remove from the specified index of a SortedList
- C# | Remove from the specified index of the StringCollection
- C# | Remove the entry at specified index from OrderedDictionary
- C# | Get or set the element at specified index in Collection<T>
- C# | Get or set the element at the specified index in ArrayList
- C# | Finding the index of first element in the array
- C# | Finding the index of last element in the array
- Finding the Index which Points Beyond the Last Element in C#
- Finding the Index of First Element of the Specified Sequence in C#
- C# | Gets or sets the element at the specified index in StringCollection
- C# | Insert an element into Collection<T> at specified index
- C# | Insert an element into the ArrayList at the specified index
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.