ArrayList list1 = new ArrayList(); list1.Add("Item1"); list1.Add("Item2"); ArrayList list2 = new ArrayList(); list2.AddRange(list1); Console.WriteLine("List2 contains:"); foreach (string item in list2) { Console.WriteLine(item); }
ArrayList list = new ArrayList(); string[] array = new string[] { "Item1", "Item2", "Item3" }; list.AddRange(array); Console.WriteLine("List contains:"); foreach (string item in list) { Console.WriteLine(item); }Here, we create an ArrayList `list` and an array `array` containing three elements. We then use the `AddRange` method to add all elements from `array` to `list`. Finally, we loop through `list` and print out its elements. The `AddRange` method is part of the `System.Collections` namespace in the .NET Framework Class Library.