zoukankan      html  css  js  c++  java
  • Array转换ArrayList

    1. Foreach

    2. ArrayList.Adapter.

    3. ArrayList to Array. 强制转换Array result = (int[])arrayList.ToArray(typeof(int))

    View Code
    class Program
        {
            static void Main(string[] args)
            {
                int[] arrayInt = new int[] { 1, 2, 3, 4 };
                ArrayList arrlistInt = new ArrayList();
                //方法一
                foreach (int a in arrayInt)
                {
                    arrlistInt.Add(a);
                }
                Console.WriteLine(arrlistInt[2].ToString());//输出3
                //方法二:
                ArrayList arrlistInt2 = ArrayList.Adapter(arrayInt);         
                Console.WriteLine(arrlistInt2[2].ToString());//输出3
                //逆向转换
                Array resultArr = (int[])arrlistInt2.ToArray(typeof(int));
                Console.WriteLine(resultArr.GetValue(2));//输出3
            }
        }
  • 相关阅读:
    webpack常见问题 收藏
    ES6 模块
    ES6 Class 类
    ES6 迭代器
    ES6 函数
    ES6 数组
    ES6 对象
    记一次pda(安卓)环境配置流程
    类型转换
    DOM事件
  • 原文地址:https://www.cnblogs.com/binyao/p/3059548.html
Copyright © 2011-2022 走看看