const和readonly

const只能声明时初始化(使用时与静态变量相似)(编译时确定)

const int a = 1017;

const string s = "abcde";

const object o = null;

 

readonly可以声明时初始化,也可以在构造函数中赋值,也可以声明时初始化后构造函数重新赋值(运行时确定)

readonly int a = 1017;

static readonly string s;

 

可看

posted @ 2019-10-08 10:49  vvull  阅读(133)  评论(0编辑  收藏  举报