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);
}
}
浙公网安备 33010602011771号