C# लिस्ट को कॉपी या क्लोन करने के लिए, सबसे पहले एक लिस्ट सेट करें:
Listlist1 = new List (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four");
अब एक स्ट्रिंग ऐरे घोषित करें और कॉपी करने के लिए CopyTo() मेथड का उपयोग करें।
string[] arr = new string[20]; list1.CopyTo(arr);
आइए लिस्ट को वन-डायमेंशनल ऐरे में कॉपी करने का पूरा कोड देखें।
उदाहरण
using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List list1 = new List(); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four"); Console.WriteLine("First list..."); foreach(string value in list1) { Console.WriteLine(value); } string[] arr = new string[20]; list1.CopyTo(arr); Console.WriteLine("After copy..."); foreach(string value in arr) { Console.WriteLine(value); } } }