I'm trying to figure a way to have a static class with constant strings that doesn't force recompilation when values from this class changes.
I've read in this highly voted comment that:
... if you change a (const) value you must also recompile all assemblies dependent on your assembly defining the constants - therefore its often safer to go the readonly route.
So I did a short experiment to check if it's true.
I have 4 projects: Program
, ProjectA
, ProjectB
& ProjectC
. Each "ProjectX" has a single class "X" while program stores main.
In C I have a single public const string someString = "some const string"
, which is referenced by a public method in B
, which in turn is referenced by a public method in A
, and A
's method is called by Program.Main
.
Whether I make someString
a const
, a static readonly
, a getter only expression bodied property or a getter only property with a property initializer, all the projects get rebuilt no matter what.
So is it true that I can have a static class that holds readonly string values that won't propagate recompilations to all depending projects once it's value is changed?