C# Array数组与ArrayList之间的互转

直接看实例吧:
        private void _btnListArray_Click(object sender, EventArgs e)
        {
            string[] a = new string[3];
            a[0] = "fd";
            a[1] = "fe";
            a[2] = "4d";

            ArrayList lst = new ArrayList();
            lst.AddRange(a);

            lst.Add("ffe");
            lst.Add("rrg");
            lst[0] = "aaaa";

            string[] b = (string[])lst.ToArray(typeof(string));
        }
执行结果:a仍然是3个元素并保持不变,lst和b都是5个元素且第一个元素是“aaaa”。

相关链接:
http://www.cnblogs.com/biandande/archive/2008/12/16/1355761.html
http://www.cnblogs.com/smallfa/archive/2008/11/23/1339296.html

Tags:

Leave a Reply