Target-Typed New Idea #1709
Unanswered
TonyValenti
asked this question in
Language Ideas
Replies: 2 comments
-
Would this only apply when a constructor argument name matches a property name? Would that property have to be read-only? |
Beta Was this translation helpful? Give feedback.
0 replies
-
The constructor arguments should not be required to match a property name. For example, I should be able to do the following:
Also, in the example above, the Name_First and Name_Last values would have to be specified since there is no default constructor. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
As I was reading:
https://github.com/dotnet/csharplang/blob/master/meetings/2018/LDM-2018-06-25.md
I had an idea regarding constructors and such. I generally really like using the initializer syntax because it gives me a clear view of the property->value mapping. I've wished this syntax was extended to regular constructors.
For example, given the following class definition:
I want to be able to new up a person as follows:
Inside of an initializer, I should be able to specify constructor parameters as if they were properties.
If I'm specifying constructor parameters, I must specify all the parameters for an overload ortherwise it is an error. I'm thinking something similar to the way that PowerShell does parameter sets would be really useful.
Beta Was this translation helpful? Give feedback.
All reactions