ArrayList를 Array로 변환하려면 C#에서 ToArray() 메서드를 사용하십시오.
먼저 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