Idea: Primary Unnamed Constructor Initializer for C# #8219
Replies: 2 comments 20 replies
-
How would As for the initializer, I would rather that it appear in some kind of block and not simply as part of the class body as the latter could easily be ambiguous. This was a big point of contention with primary constructors as they were first discussed back in the C# 6.0 timeframe (unfortunately those conversations are buried in the CodePlex archive so it's not possible to easily link to them.) |
Beta Was this translation helpful? Give feedback.
-
There is already a Final Initializer proposal #6591 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, C# language enthusiasts,
I would like to share an idea for a new feature in the C# language: the Primary Unnamed Constructor Initializer. This feature aims to streamline object initialization by allowing methods or events to be set directly in the constructor initializer, providing a more concise and readable syntax. You can find the concept code and more details in my repository here: Primary Unnamed Constructor Initializer Concept.
Motivation:
The Primary Unnamed Constructor Initializer builds upon the existing primary constructor concept by enabling more flexible and expressive object initialization. This feature would improve code readability and maintainability, especially when dealing with complex initialization logic. This would be the successor of the Primary Constructor introduced in C# 12.
Idea:
The primary unnamed constructor initializer can be placed flexiblely. Here is an example to illustrate its usage:
Explanation:
Start
method invokes theOnStart
event, demonstrating how the initializer sets up the necessary functionality.Benefits:
Contribution:
I encourage the community to review the concept and provide feedback on its potential inclusion in the C# language. Let's discuss how this feature could enhance our coding experience and bring additional clarity to object initialization in C#.
Thank you for considering this idea.
Beta Was this translation helpful? Give feedback.
All reactions