C# const 和 static readonly的区别

修饰符 可修饰的变量 初始化位置 不变性 生命周期
Const 基本类型 声明的时候初始化 编译时常量 编译器存入变量metadata中,使用时不需要加载到ram
static readonly 不限 声明+构造器 运行时常量,仅仅是变量持有的引用不可变,不限制引用类型成员的修改 初次构造后确定

 

 

注意点:
由于const变量的值在编译期间就已经将其存入metadata中, 程序中使用常量其实已经直接将其替换成常量值了(可以通过 IL 查看),所以在 client-> lib这样引用关系的应用中,如果要修改存在于lib中的常量,单单重新编译发布 lib是不会对 client起作用的, 需要重发 client。
posted @ 2019-06-14 15:22  <--青青子衿-->  阅读(92)  评论(0编辑  收藏  举报
// /**/ // 在页脚Html代码 引入 // function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; $("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);