ArrayList.GetRange(Int32, Int32) Method is used to get an ArrayList which will represent a subset of the elements in the source ArrayList.
public virtual System.Collections.ArrayList GetRange (int index, int count);
index: It is of Int32 type and represents the zero-based ArrayList index at which the range starts.
count: It is of Int32 type and represents the number of elements in the range.
Return Value: This method returns an ArrayList which represents a subset of the elements in the source ArrayList.
- ArgumentOutOfRangeException: If the value of the index is less than zero, or if the value of count is less than zero.
- ArgumentException: If the value of an index and count does not denote a valid range of elements in the ArrayList.
Below programs illustrate the above-discussed method:
Elements are: Welcome to Geeks for Geeks portal Now elements are: Welcome to This is C# tutorial
System.ArgumentOutOfRangeException: Non-negative number required.
Parameter name: index
- C# | Copy the elements of collection over a range of elements in ArrayList
- C# | Sort the elements in the ArrayList
- C# | Adding the elements to the end of the ArrayList
- C# | Remove all elements from the ArrayList
- C# | Adding elements to the end of the ArrayList
- C# | Get or set the number of elements that the ArrayList can contain
- C# | ArrayList whose elements are copies of the specified value
- C# | Copying the elements of ArrayList to a new array
- C# | Remove a range of elements from the ArrayList
- C# | Get the number of elements actually contained in the ArrayList
- C# | Getting an enumerator for a range of elements in the ArrayList
- C# | Reverse the order of the elements in the entire ArrayList or in the specified range
- C# | Sets the capacity to the actual number of elements in the ArrayList
- ArrayList in C#
- C# | Add an object to the end of the ArrayList
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.