zoukankan      html  css  js  c++  java
  • 装箱和拆箱

     装箱和拆箱
          1、装箱:值类型----->引用类型
          2、拆箱:引用类型----->值类型
          3、我们判断是否发生了拆箱或者装箱,首先要判断这两种数据类型是否存在继承关系。
          4、你装箱的时候拿什么类型装的箱,你拆的时候,就得拿什么类型去拆。

          5   、代码实测比较

       //是否发生裝箱和拆箱的效率比较
                Stopwatch sw = new Stopwatch();
                sw.Start();
                //ArrayList list = new ArrayList();  //运行时间为:00:00:00.0007680
                List<int> list = new List<int>();   //运行时间为:00:00:00.0002001
                for (int i = 0; i <= 10000; i++) {
                    list.Add(i); //此处涉及到int 类型转换为Object类型
                }
                sw.Stop();
                Console.WriteLine(sw.Elapsed);//获取当前实测量得出的运行总时间
                Console.ReadKey();

        

  • 相关阅读:
    120.三角形最短路径(leetcode)
    Python Pycharm中灵活运用debugger
    POJ 1284
    POJ 2407
    POJ 1811
    HDU 1164
    HDU 4228
    HDU 2521
    HDU 4133
    ZOJ 2562 反素数
  • 原文地址:https://www.cnblogs.com/netlws/p/8832096.html
Copyright © 2011-2022 走看看