feibeng

导航

 
using System;
using System.Collections;
using System.Collections.Generic;

public class MyClass
{
    public static void Main()
    {
        List<int> iList = new List<int>();
        int[] iArray = new int[0];
        ArrayList al = new ArrayList();
        int count = 10;
        //==========================
        //增加元素
        //==========================
        for (int i = 0; i < count; ++i)
        {
            iList.Add(i);
        }

        iArray = new int[count];//需要初始化
        for (int i = 0; i < count; ++i)
        {
            iArray[i] = i;
        }

        for (int i = 0; i < count; ++i)
        {
            al.Add(i);//这里有box操作
        }
        //==========================
        //输出
        //==========================
        foreach (int i in iList)
        {
            Console.WriteLine(i);
        }

        foreach (int i in iArray)
        {
            Console.WriteLine(i);
        }

        foreach (object o in al)
        {
            Console.WriteLine(o);//这里有unbox操作
        }
        //============================
        //继续增加元素
        //============================
        iList.Add(count);

        iArray = new int[count + 1];//需要重新分配内存
        for (int i = 0; i < count; ++i)
        {
            iArray[i] = i;
        }
        iArray[count] = count;

        al.Add(count);



    }

}
posted on 2010-01-04 14:00  甜橙子和香板栗  阅读(404)  评论(0)    收藏  举报