EazyChange

导航

 

第一段代码:用arraylist

Stopwatch sw = new Stopwatch();
            sw.Start();
            var list = new ArrayList();
            int temp;
            for (int i = 0; i < 1000000; i++)
            {
                list.Add(i);
                temp = (int)list[i];
            }
            list = null;
           
            sw.Stop();          
            Console.WriteLine(sw.ElapsedMilliseconds.ToString());
            sw = null;

第二段代码使用List<>。

Stopwatch sw = new Stopwatch();
            sw.Start();
            var list = new List<>();
            int temp;
            for (int i = 0; i < 1000000; i++)
            {
                list.Add(i);
                temp = list[i];
            }
            list = null;
           
            sw.Stop();          
            Console.WriteLine(sw.ElapsedMilliseconds.ToString());
            sw = null;

时间:

posted on 2014-04-20 14:08  EazyChange  阅读(138)  评论(0编辑  收藏  举报