The name DefaultValue is private, but the number 2 is still the number 2 .
Since DefaultValue is private, we cannot access Program.DefaultValue from outside Program . Presumably, we would not particularly want to.
And since we still decided to define DefaultValue , this is apparently what we care about when we work on how the Program works.
So, when we come to the definition of the default value for DoSomething , presumably there is some logical reason why the required value there will be the same as the value of DefaultValue .
And as such, it may be useful to use this constant there, for the same reasons that we find the constants useful anywhere.
And since DefaultValue is just a Program specific way of saying 2 , there is no real reason why we cannot.
Of course, the metadata will reflect this as 2 , and not (without meaning for the external) DefaultValue , but then it will be executed if const was public anyway (the metadata about the default values give only the value, and not regardless of whether it with any defined constants).
Therefore, there are no shortcomings.
So, given that:
- There is an advantage for the performer.
- There is no flaw for the user just using literal
2 . - Preventing this would be to introduce a special rule as an exception to the rule in which certain constants can be used wherever a constant value from a literal can be.
Why not?
source share