Replies: 3 comments 3 replies
-
In my opinion semi-auto properties are less controversial than primary constructors, and they were delayed to C# 13, so primary constructors should be too. A little more time to "do it right" would be probably be best for the future of the language. Alternatively, interceptors have set a precedent for adding experimental features to the language. Since most of the implementation work has already been done on primary constructors, they could be given a similar treatment in C# 12 and promoted to a full feature in C# 13, perhaps with some breaking changes based on feedback from the C# 12 version. |
Beta Was this translation helpful? Give feedback.
-
WRT primary constructor parameters, did you consider going with Option 4 (readonly by default) for v12 as a possibly interim measure, since it can always be relaxed in a future version of C#? For example, C#12 could have primary constructor parameters that are readonly, then (based on wider community feedback) C#13 could allow you to mutate them during initialisation. It's a way of being able to defer that decision without having to delay the whole feature. |
Beta Was this translation helpful? Give feedback.
-
👍 I'm OK with either option 2 or 3. For 2: The primary use case would be dependency injection where no validation is necessary. For other cases, if value clamping or value fallback is necessary, we can fall back to a normal field. For 3: It seems to be better at both sides. It provides mutability inside the constructor (for value clamping/fallback), while read-only elsewhere (where I'm really concerned with). In addition, it is consistent with records. Perfect. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2023/LDM-2023-07-26.md
Agenda
readonly
Beta Was this translation helpful? Give feedback.
All reactions