I have a project which utilizes many global constants. Eventually I am planning to extract some parts of the program and create assemblies of its own.
Is it worthy (or is it possible?) to create an assembly for global constants alone (viz, GlobalConstants.dll), so that I can use this assembly in future assemblies?
This method will help me do less coding, and I can keep the same name for the constants across the projects.
While it is certainly possible to do and maybe even a pretty good idea, you should be aware of the fact that the C# compiler treats constants as values and not as references.
With this I mean that the C# compiler will replace all instances of the constant in you code and replace the "variable" with the value.
This means that even if you update the assembly GlobalConstants.dll
and copy it to one of the applications you have, you will need to recompile that application. Not doing so, will cause the application to use the old constant values.
To overcome this problem, you can simply use public static readonly
instead of public const
as the readonly
modifier differs from the const
in that it is treated by the C# compiler as a reference in code rather than a value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With