-
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: Allow "this" as the constructor name #1335
Comments
A |
Ah, great point. Closing. |
💡 What about copying and pasting only the constructor parameter list, and then using a code action to generate fields from the parameter list? |
may be using ctor instead of this
|
Note: there is nothing actually syntactically wrong with allowing 'this' as the constructor name. yes, it shares a prefix with indexers. but they have very different code after the 'this' keyword. 'this' works well for me in both situations. One explains how to construct a new 'this', and one explains how you could index as instance of 'this'. |
@TruePluto I've had the same thought ... but they try to avoid adding new keywords. (That was explained to me once when I asked about the weird way that @CyrusNajmabadi That's a good point. Indexers have a return-type, so without a type it could indicate the constructor. |
Which is exactly the same grammatical difference between constructors and methods today :) So it makes a bunch of sense. |
|
Some languages use the
this
keyword as the name of the constructor. It seems sensible to me so I thought I'd float the suggestion. I suppose it also implies~this
for finalizers.While building and maintaining DI-aware libraries, I often find myself cutting-and-pasting constructors and this change would save a (small) step having to rename the constructor to match the new class.
The text was updated successfully, but these errors were encountered: