const = value assigned at Compile time and unchangeable once established.
readonly = value assigned at run time and unchangeable once established.
static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time.
Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference.
If the value will never change, then const is fine - Zero etc make reasonable consts ;-p Other than that, static properties are more common.
Const values are burned directly into the call-site; this is double edged:
it is useless if the value is fetched at runtime, perhaps from configif you change the value of a const, you need to rebuild all the clientsbut it can be faster, as it avoids a method call......which might sometimes have been inlined by the JIT anywayIf the value will never change, then const is fine - Zero etc make reasonable consts ;-p Other than that, static properties are more common.
转载于:https://www.cnblogs.com/EasonWu/p/const-vs-readonly.html
相关资源:JAVA上百实例源码以及开源项目