C# | Copy the elements of collection over a range of elements in ArrayList
ArrayList.SetRange(Int32, ICollection) Method is used to copy the elements of a collection over a range of elements in the ArrayList.
public virtual void SetRange (int index, System.Collections.ICollection c);
index: It is a zero-based ArrayList index at which to start copying the elements of c. The type of this parameter is System.Int32.
c: It is an ICollection whose elements to copy to the ArrayList. The collection itself cannot be null, but it can contain elements that are null.
- ArgumentNullException: If the value of c is null.
- NotSupportedException: If the ArrayList is read-only.
- ArgumentOutOfRangeException: If the index is less than zero or [index + number of elements in c] > Count.
Below given are some examples to understand the implementation in a better way:
ArrayList is = This ArrayList is = is ArrayList is = C# ArrayList is = Tutorial ArrayList is = s ArrayList is = G ArrayList is = F ArrayList is = G
String from index number 0 to 6: Hello Welcome to online portal of After SetRange() Method: Hello This is C# tutorial.