ArrayList al=new ArrayList();
al.Add(0);
al.Add(1);
al.Add("mike");
foreach (var item in al)
{
Console.WriteLine(item);
}
ArrayList al=new ArrayList();
al.Add(0);
al.Add(1);
al.Add("mike");
int t = 0;
foreach (int item in al)
{
t += item;
}
var intArr = new int[] {0, 1, 2, 3};
ArrayList al=new ArrayList(intArr);
public virtual void InsertRange(int index, ICollection c)
{
if (c == null)
{
throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection"));
}
if ((index < 0) || (index > this._size))
{
throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
}
int count = c.Count;
if (count > 0)
{
this.EnsureCapacity(this._size + count);
if (index < this._size)
{
Array.Copy(this._items, index, this._items, index + count, this._size - index);
}
object[] array = new object[count];
c.CopyTo(array, 0);
array.CopyTo(this._items, index);
this._size += count;
this._version++;
}
}
List<int> intList = new List<int>();
intList.Add(1);
intList.Add(2);
//intList.Add("mike");
foreach (var item in intList)
{
Console.WriteLine(item);
}
static void Main(string[] args)
{
Console.WriteLine("开始测试ArrayList:");
TestBegin();
TestArrayList();
TestEnd();
Console.WriteLine("开始测试List<T>:");
TestBegin();
TestGenericList();
TestEnd();
}
static int collectionCount = 0;
static Stopwatch watch = null;
static int testCount = 10000000;
static void TestBegin()
{
GC.Collect(); //强制对所有代码进行即时垃圾回收
GC.WaitForPendingFinalizers(); //挂起线程,执行终结器队列中的终结器(即析构方法)
GC.Collect(); //再次对所有代码进行垃圾回收,主要包括从终结器队列中出来的对象
collectionCount = GC.CollectionCount(0); //返回在0代码中执行的垃圾回收次数
watch = new Stopwatch();
watch.Start();
}
static void TestEnd()
{
watch.Stop();
Console.WriteLine("耗时:" + watch.ElapsedMilliseconds.ToString());
Console.WriteLine("垃圾回收次数:" + (GC.CollectionCount(0) - collectionCount));
}
static void TestArrayList()
{
ArrayList al = new ArrayList();
int temp = 0;
for (int i = 0; i < testCount; i++)
{
al.Add(i);
temp = (int)al[i];
}
al = null;
}
static void TestGenericList()
{
List<int> listT = new List<int>();
int temp = 0;
for (int i = 0; i < testCount; i++)
{
listT.Add(i);
temp = listT[i];
}
listT = null;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有