What is the difference between const and static readonly?
Monday, May 19th, 2008The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, whereas the value of a const field is set to a compile time constant.
In the static readonly case, the containing class is allowed to modify it only
* in the variable declaration (through a variable initializer).
* in the static constructor (instance constructors, if it’s not static) .
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.