第一段代碼:用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;
時間: