A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Kaitong 中级黑马   /  2014-4-4 23:49  /  1252 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 Kaitong 于 2014-4-5 21:04 编辑

用哪种方法好些?最好能有个例子,谢谢

评分

参与人数 1技术分 +1 收起 理由
czwanglei + 1

查看全部评分

4 个回复

倒序浏览
class Program
{
    static void Main()
    {
        int[] arr = { 0, 1, 2, 3, 4 };
        List<int> list = new List<int>();
        for (int x = 5; x < 10; x++)
        {
            list.Add(x);
        }
        ProcessItems<int>(arr);
        ProcessItems<int>(list);
    }
    static void ProcessItems<T>(IList<T> coll)
    {
        foreach (T item in coll)
        {
            System.Console.Write(item.ToString() + " ");
        }
        System.Console.WriteLine();
    }
}


评分

参与人数 1技术分 +1 收起 理由
czwanglei + 1

查看全部评分

回复 使用道具 举报
遍历Array,在遍历中调用ArrayList.Add()逐条添加

评分

参与人数 1技术分 +1 收起 理由
czwanglei + 1

查看全部评分

回复 使用道具 举报
  1.             int[] it = new int[] { 1, 2, 3, 4, 5, 6 };
  2.             ArrayList al = new ArrayList();
  3.             al.AddRange(it);
复制代码

不知道是不是这样

评分

参与人数 1技术分 +1 收起 理由
czwanglei + 1

查看全部评分

回复 使用道具 举报
目前我也是学习.NET  浏览你们的问题学习学习
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马