নির্দিষ্ট সূচক থেকে শুরু করে একটি 1-D অ্যারেতে সম্পূর্ণ ArrayList কপি করতে, কোডটি নিম্নরূপ -
উদাহরণ
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList list = new ArrayList(); list.Add("PQ"); list.Add("RS"); list.Add("TU"); list.Add("UV"); list.Add("WX"); list.Add("YZ"); Console.WriteLine("ArrayList elements..."); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } String[] strArr = new String[6] {"One", "Two", "Three", "Four", "Five", "Six"}; Console.WriteLine("\nArray elements..."); for (int i = 0; i < strArr.Length; i++) { Console.WriteLine(strArr[i]); } list.CopyTo(strArr, 0); Console.WriteLine("\nArray elements (updated)..."); for (int i = 0; i < strArr.Length; i++) { Console.WriteLine(strArr[i]); } } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেArrayList elements... PQ RS TU UV WX YZ Array elements... One Two Three Four Five Six Array elements (updated)... PQ RS TU UV WX YZ
উদাহরণ
এখন আরেকটি উদাহরণ দেখা যাক -
using System; using System.Collections; public class Demo { public static void Main(){ ArrayList list = new ArrayList(); list.Add(100); list.Add(200); Console.WriteLine("ArrayList elements..."); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } int[] intArr = new int[5] {10, 20, 30, 40, 50}; Console.WriteLine("\nArray elements..."); for (int i = 0; i < intArr.Length; i++) { Console.WriteLine(intArr[i]); } list.CopyTo(intArr, 0); Console.WriteLine("\nArray elements (updated)..."); for (int i = 0; i < intArr.Length; i++) { Console.WriteLine(intArr[i]); } } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেArrayList elements... 100 200 Array elements... 10 20 30 40 50 Array elements (updated)... 100 200 30 40 50