ArrayList के अंत में तत्वों को जोड़ने के लिए, कोड इस प्रकार है -
उदाहरण
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list = new ArrayList(); list.Add("Andy"); list.Add("Gary"); list.Add("Katie"); list.Add("Amy"); Console.WriteLine("Elements in ArrayList..."); foreach (string res in list) { Console.WriteLine(res); } string[] strArr = { "John", "Jacob" }; list.AddRange(strArr); Console.WriteLine("Elements in ArrayList...UPDATED"); foreach(String str in list) { Console.WriteLine(str); } } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
Elements in ArrayList... Andy Gary Katie Amy Elements in ArrayList...UPDATED Andy Gary Katie Amy John Jacob
उदाहरण
आइए एक और उदाहरण देखें -
using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list = new ArrayList(); list.Add("Andy"); list.Add("Gary"); list.Add("Katie"); list.Add("Amy"); Console.WriteLine("Elements in ArrayList..."); foreach (string res in list) { Console.WriteLine(res); } string[] strArr = { "John", "Jacob" }; list.AddRange(strArr); Console.WriteLine("Elements in ArrayList...UPDATED"); foreach(String str in list) { Console.WriteLine(str); } string[] strArr2 = { "Tim", "Tom", "David" }; list.AddRange(strArr2); Console.WriteLine("Elements in ArrayList...UPDATED"); foreach(String str in list) { Console.WriteLine(str); } } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
Elements in ArrayList... Andy Gary Katie Amy Elements in ArrayList...UPDATED Andy Gary Katie Amy John Jacob Elements in ArrayList...UPDATED Andy Gary Katie Amy John Jacob Tim Tom David