C# | Getting a subset of the elements from the source ArrayList
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