zoukankan      html  css  js  c++  java
  • const常量和readonly常量区别

    1、const常量为静态常量;readonly常量为动态常量;
    2、const常量在编译时值被确定,在运行时值为编译时值;readonly常量,在编译时为类型的默认值(非指定的默认值),在运行时值被确定;
    3、const常量无内存消耗;readonly存常量有内存消耗;
    4、const常量为引用类型,值为string.Empty或null;readonly为值类型,可以为任何值;

    如:
     const int A=1;
     readonly int B=1;
     -------------------
     编译时:A=1;B=0;
     运行时:A=1;B=1;
     A=1;
     B=1;
     -------------------
     const int A=B+1;
     readonly int B=1;
     -------------------
     编译时:B=0;A=0+1=1;
     运行时:A=1;B=1;
     A=1;
     B=1;
     -------------------
     const int A=B+1const int B=1;
     -------------------
     编译时:B=1;A=1+1=2;
     运行时:A=2;B=1;
     A=2;
     B=1;
     -------------------
  • 相关阅读:
    自我介绍
    币值转换
    打印沙漏
    对我影响最大的三位老师

    pta
    pta-3
    学习计划
    对我有影响的三个老师
    介绍自己
  • 原文地址:https://www.cnblogs.com/raowenbin/p/4060124.html
Copyright © 2011-2022 走看看