.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
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-ArrayList-to-Array-New
https://www.ez2o.com/Blog/Post/55
https://www.ez2o.com/Blog/Post/csharp-ArrayList-to-Array-New
https://www.ez2o.com/Blog/Post/55