List<T>.RemoveRange(Int32, Int32) Method is used to remove a range of elements from 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 RemoveRange (int index, int count);
index: It is the zero-based starting index of the range of elements which is to be removed.
count: It is the number of the elements which is to be removed.
- ArgumentOutOfRangeException: If the index is less than zero or Count is less than zero.
- ArgumentException: If the index and Count do not denote a valid range of elements in the List<T>.
Below programs illustrate the use of List<T>.RemoveRange(Int32, Int32) Method:
Elements in List: Geeks For Geeks GFG C# Tutorials GeeksforGeeks After Removing of elements: Geeks For Geeks C# Tutorials GeeksforGeeks
Elements in List: 1 2 3 4 5 6 7 After Removing of elements: 1 2 3 6 7
- C# | Removing all the elements from the List
- C# | Removing the specified element from the List
- C# | Reverse the order of the elements in the entire List or in the specified range
- C# | Copy the elements of collection over a range of elements in ArrayList
- C# | Removing all entries from the StringDictionary
- C# | Removing all entries from HybridDictionary
- C# | Removing the specified key entry from HybridDictionary
- C# | Removing first occurrence of object from Collection<T>
- C# | Removing all nodes from LinkedList<T>
- C# | Removing the node at the start of the LinkedList<T>
- C# | Removing the node at the end of LinkedList<T>
- C# | Removing the specified node from the LinkedList<T>
- C# | Removing first occurrence of specified value from LinkedList<T>
- Removing the object from the top of the Stack in C#
- C# | Remove a range of elements from the ArrayList
- C# | Reverse the order of the elements in the entire ArrayList or in the specified range
- C# | Getting an enumerator for a range of elements in the ArrayList
- Finding all the Elements of a Range from Start to End in C#
- How to sort a list in C# | List.Sort() Method Set -1
- How to sort a list in C# | List.Sort() Method Set -2
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.