-
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
Proposal: remove the need to explicitly specify the type for initialised fields #601
Comments
This is a duplicate of dotnet/roslyn#11551, which was closed by @gafter, who said:
There's also an article by Eric Lippert, who explains the issues with implementing this. (Though the article predates Roslyn, so I'm not sure how much of it is still relevant.) |
I'd be happy with var fields, but only if they come with one of the main benefits of |
Fair point. The "added bonus" was a bit of an after thought. Upon reflection, I agree with you that it would be a bad idea. Removed. |
What about the other way around (#100), Dictionary<string, Func<int>> _someMap = new (); |
@DavidArno why did you close this? I want it. |
Ah, I maybe got a bit carried away. I was unsubscribing from threads and closing my issues to allow me a period away from here, with the aim of returning at some point in the future with a more positive attitude. Maybe this one didn't need closing though, so I've re-opened it. |
Thanks man. |
Alright, I won't object. |
Closing this makes me sad - I am not sure unlikely to happen is a good reason to lose something people would like to happen just because it might not be in the next version. |
@NetMage The main reason that Ask yourself: Is it really worth spending many, many man-hours (which then can't be spent on other language features) and increasing the compiler's complexity by that much, when there's a far simpler, far more efficient, near-equivalent alternative on the table as well? |
Currently, C# supports
var
for local variables, but it is still necessary to specify the type for fields, even if their type could be derived from the initialisation expression.Allow
var
andreadonly
to be used to declare implicitly typed fields:As an added bonus, fields initialised by the constructor could have their types inferred too, though this may be tricky to implement in a performant fashion:The text was updated successfully, but these errors were encountered: