किसी ArrayList को Array में बदलने के लिए, ToArray () विधि का उपयोग C# में करें।
सबसे पहले, एक ArrayList सेट करें -
ArrayList arrList = new ArrayList();
arrList.Add("one");
arrList.Add("two");
arrList.Add("three"); अब, कनवर्ट करने के लिए, ToArray() विधि का उपयोग करें -
arrList.ToArray(typeof(string)) as string[];
आइए देखें पूरा कोड -
उदाहरण
using System;
using System.Collections;
public class Program {
public static void Main() {
ArrayList arrList = new ArrayList();
arrList.Add("one");
arrList.Add("two");
arrList.Add("three");
string[] arr = arrList.ToArray(typeof(string)) as string[];
foreach (string res in arr) {
Console.WriteLine(res);
}
}
} आउटपुट
one two three