Const vs Static vs Readonly
Here's what you need to know about using const
, static
, and readonly
:
- If you know the value will never, ever, ever change for any reason, use
const
. (Other Assemblies that use this value need to be recompiled before they get the new value) - If you're unsure of whether or not the value will change, but you don't want other classes or code to be able to change it, use
readonly
. - If you need a field to be a property of a type, and not a property of an instance of that type, use
static
. - A
const
value is also implicitlystatic
.