Updating the value of a public constant should be viewed as an interface change. You must recompile all code that references that constant
- 1. C# Language Idioms
- from Effective C# (Covers C# 4.0): 50 Specific Ways to Improve Your C#, Second Edition
- Publisher: Addison-Wesley Professional
- Released: March 2010
Instances to a constant will be replaced with the value it represents in the IL, rather than a reference to it. Therefore, other code which references a constant within the current file will not be automatically updated without being explicitly recompiled.
The readonly modifier solves this problem by not replacing it with a value. Therefore, its value will be correct even if the other code isn't recompiled. Although slightly less efficient, this solves a problem that could be hard to nail down.
Share this highlighthttp://www.safaribooksonline.com/a/effective-c-covers/1155040/