C# | Adding elements to the end of the ArrayList Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report AddRange(ICollection) Method is used to add the elements of an ICollection to the end of the ArrayList. Or in other words, this method is used to add the multiple elements from other collection into an ArrayList. Here elements are defined as the primitive or non-primitive type. Syntax: public virtual void AddRange (ICollection col); Here, col is an ICollection whose elements should be added to the end of the ArrayList. The collection itself cannot be null, but it can contain null elements. Exception: If the value of col is null then this method will give ArgumentNullException. This method will gives NotSupportedException if the ArrayList is read-only, or the ArrayList has a fixed size Below given are some examples to understand the implementation in a better way: Example 1: CSharp // C# program to illustrate the AddRange() Method using System; using System.Collections; class GFG { // Main method public static void Main() { // Creates and initializes a new ArrayList ArrayList mylist = new ArrayList(); mylist.Add("C# "); mylist.Add("DSA "); mylist.Add("Java "); mylist.Add("CPP"); // Creates and initializes a new Queue Queue mydata = new Queue(); mydata.Enqueue("C "); mydata.Enqueue("Python "); mydata.Enqueue("HTML "); mydata.Enqueue("CSS "); mydata.Enqueue("JavaScript "); mydata.Enqueue("Ruby"); // Displays the ArrayList and the Queue. Console.Write("The original ArrayList: "); Data(mylist); Console.Write("The original Queue: "); Data(mydata); // Copies the elements of the queue to the end of the ArrayList. mylist.AddRange(mydata); // Displays the new ArrayList. Console.Write("The new ArrayList is: "); Data(mylist); } // method to display the ArrayList // and Queue elements public static void Data(IEnumerable mylis) { foreach(string str in mylis) Console.Write("{0}", str); Console.WriteLine(); } } Output: The original ArrayList: C# DSA Java CPP The original Queue: C Python HTML CSS JavaScript Ruby The new ArrayList is: C# DSA Java CPPC Python HTML CSS JavaScript Ruby Example 2: CSharp // C# program to illustrate // the AddRange() Method using System; using System.Collections; public class GFG { // Main method public static void Main() { // Creates and initializes a new ArrayList. ArrayList mylist = new ArrayList(); mylist.Add(5); mylist.Add(10); mylist.Add(15); mylist.Add(20); mylist.Add(25); // Creates and initializes a new ArrayList. ArrayList mydata = new ArrayList(); mydata.Add(30); mydata.Add(35); mydata.Add(40); mydata.Add(45); mydata.Add(50); // Displays both ArrayList. Console.WriteLine("The ArrayList 1: "); foreach(int i in mylist) { Console.WriteLine(i); } Console.WriteLine("The ArrayList 2: "); foreach(int j in mydata) { Console.WriteLine(j); } // Copies the elements of the mydata // to the end of the mylist mylist.AddRange(mydata); // Displays the new ArrayList. Console.WriteLine("The new ArrayList is :"); for (int k = 0; k < mylist.Count; k++) Console.WriteLine(mylist[k]); } } Output: The ArrayList 1: 5 10 15 20 25 The ArrayList 2: 30 35 40 45 50 The new ArrayList is : 5 10 15 20 25 30 35 40 45 50 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist.addrange?view=netframework-4.7.2#System_Collections_ArrayList_AddRange_System_Collections_ICollection_ Comment More infoAdvertise with us Next Article C# | Adding elements to the end of the ArrayList A ankita_saini Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Collections-ArrayList Similar Reads C# | Adding the elements to the end of the ArrayList ArrayList.AddRange(ICollection) Method is used to add the elements of an ICollection to the end of the ArrayList. Syntax: public virtual void AddRange (System.Collections.ICollection c); Here, c is the ICollection whose elements should be added to the end of the ArrayList. The collection itself cann 2 min read C# | Add an object to the end of the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Add(Object) method adds an object to the end of the ArrayList. Pr 2 min read C# | Copying the elements of ArrayList to a new array ArrayList.ToArray Method is used to copy the elements of the ArrayList to a new array. This method contains two methods in its overload list as follows: ToArray()ToArray(Type)ToArray() This method is used to copy the elements of the ArrayList to a new Object array. The elements are copied using Arra 2 min read C# | Adding an element to the List List.Add(T) Method is used to add an object to the end of the List. 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 eq 2 min read C# | Remove all elements from the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Clear method is used to remove all the elements from the ArrayLis 3 min read Like