[Proposal]: Allow skipping constructor of Positional Records #4178
Unanswered
SWATOPLUS
asked this question in
Language Ideas
Replies: 2 comments 4 replies
-
Because it was intentionally designed to work like this. It's one of the defining features of a positional record. Nominal records exist for those cases where you don't want a required constructor. |
Beta Was this translation helpful? Give feedback.
4 replies
-
If the goal is to improve readability, wouldn't using the standard constructor with named arguments work? var stats = new SequenceStats(
Average: scores.Average(),
Median: scores.Median(),
StandardDeviation: scores.StandardDeviation(),
Minimum: scores.Min(),
Maximum: scores.Max()); This is just as readable using the object initializer, and with named arguments you can even put the arguments in whichever order you prefer. |
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.
-
Allow skipping constructor of Positional Records
Summary
When I use some Positional Record I want to be able initialize propertities using object initializer.
Motivation
This can improve readability of object construction.
Detailed design
Drawbacks
None
Alternatives
Unresolved questions
Why it didn't shipped in C#9.0?
Beta Was this translation helpful? Give feedback.
All reactions