1    ArrayList arrInt = new ArrayList();
 2                 //用stopwatch来计时 运行的时间
 3             Stopwatch watch = new Stopwatch();
 4             watch.Start();
 5             for (int i = 0; i < 1000000; i++)
 6             {
 7                 arrInt.Add(i);
 8             }
 9             watch.Stop();
10             Console.WriteLine(watch.Elapsed);
11             Console.ReadKey();
12 
13 
14            // 使用泛型集合避免装箱和拆箱。
15             List<int> arrInt1 = new List<int>();
16             Stopwatch watch2 = new Stopwatch();
17             watch2.Start();
18             for (int i = 0; i < 1000000; i++)
19             {
20                 arrInt1.Add(i);
21             }
22             watch2.Stop();
23             Console.WriteLine(watch.Elapsed);
24             Console.ReadKey();

 

相关文章:

  • 2021-07-25
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2021-08-13
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-02-03
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
相关资源
相似解决方案