-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional type information on local constants. #2713
Comments
See also #188 which would allow |
And further, as per the discussion in #188, using private void SomeMethod()
{
let baz = 2f; // readonly, ie constant
let bar = new C(); // readonly, ie constant
var foo = 1; // mutable
} thus we get a consistent way of expressing local "constants" for all types, not just those allowed with the |
Personally I don't see the value in this. Constant locals must be of type |
But @john-h-k take a look at enums then:
versus
It's definitely worth it in my oppinion. |
Closing as duplicate of #106 |
At the moment it is possible to prefix a local variable with var and the type information is inferred from the assignment:
For example:
However when declaring local constants it is necessary to also write a type. Like here
This feels a bit inconsistent. Maybe
const baz = 2f;
should be allowed for local constants, that way we could writeThis would be both more constant and convenient. Additionally it would encourage using immutable values when possible.
The text was updated successfully, but these errors were encountered: