The best way is probably to read the value before creating the class that should hold it, so you can pass it to the constructor and put it in the readonly field. But since you ruled it out in an obvious way ...
You can use a read-only property (a property with get but not set) and always access it through the property, except where you originally set the value.
If you donβt even want to risk changing it from your own class, create a class to βwrapβ the value. This class will do nothing more than read the value if necessary for the first time and set it as a read-only property for your consumer classes.
But no matter what method you choose, do not use the "1970 C macro constant" (ALL_CAPS) for your constant :-)
source share