ArrayList 轉為 Array ArrayList 轉為 Array
  .NET       ez      2011-11-30

不須透過迴圈,直接將ArrayList專為Array

using System;
using System.Collections;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList ALs = new ArrayList() { "a", "b", "c", "d", "e" };
            ArrayList ALi = new ArrayList() { 1, 2, 3, 4, 5 };

            string[] s = (string[])ALs.ToArray(typeof(string)); //字串轉換
            int[] i = (int[])ALi.ToArray(Type.GetType("System.Int32")); //數值轉換

            Console.WriteLine(String.Join(",", s));
            Console.WriteLine(String.Join(",", i));
        }
    }
}

標籤:   .NET

我要留言