第一段代码:用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;
时间:
原文:http://www.cnblogs.com/wyc199288/p/3676371.html