I need to check for a certain version in one of my components. For that reason I just wanted to introduce a public const int on which I could test.
However, I just read in this SO post When, if ever, should we use const? that it’s probably a bad idea to use a const whenever something changes in the future.
What’s the best way to do that? Using a public readonly int? Using an attribute? I can’t use AssemblyVersion or AssemblyFileVersion as those are not in my hand…
Thanks!
I’d use the const (in fact, I do use it for that).
readonlyis initialised at run-time, in fact, it can have a different value every time you run the application [1]. Because of that propery, I’d say it is less useful for a version number.A version number is (should be?) hard-coded at compile time, which would be a
const. Comparison could be a#definein C.I reckon that because of this difference, a
constdoesn’t use data memory, as areadonlydoes. I have no sources for that though.[1] http://en.csharp-online.net/const,_static_and_readonly