C# C# Console Application

ArrayList GetRange() method in C#1 min read

.Net framework ArrayList.GetRange() method allow us to return an ArrayList which represents a subset of the elements in the source ArrayList. the arraylist GetRange(index, count) method exists under System.Collections namespace. this method has two required parameters named ‘index’ and ‘count’.

both parameters value data type is System.Int32. the ‘index’ parameter value represents the zero-based ArrayList index at which the range starts. and the ‘count’ parameter value represents the number of elements in the range. the arraylist GetRange() method return value type is System.Collections.ArrayList which is an ArrayList that represents a subset of the elements in the source ArrayList.




the GetRange() method throw ArgumentOutOfRangeException exception, if the ‘index’ is less than zero or ‘count’ is less than zero. method also throw ArgumentException, if the ‘index’ and ‘count’ do not denote a valid range of elements in the arraylist.

the following console c# example code demonstrate us how can we get an arraylist which represents a subset of the elements in the source arraylist programmatically at run time in an console application.

C# Code:

 

Output:

 

Leave a Comment