-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add reason for using primary constructor #50741
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
base: main
Are you sure you want to change the base?
Conversation
Explain the benefits and trade-offs of using primary constructors in C#.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds an explanatory paragraph about the benefits and trade-offs of using primary constructors in C# to the IDE0290 style rule documentation. The addition aims to help developers understand when and why to use primary constructors versus traditional constructor syntax.
Key Changes
- Adds a new paragraph explaining the purpose and trade-offs of primary constructors
- Provides context about constructor generality versus declaration syntax complexity
|
|
||
| This rule flags classes that can use a [primary constructor](../../../csharp/programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) instead of a separate constructor definition. You define a primary constructor by placing any constructor parameters in parentheses following the type name. A primary constructor indicates that these parameters are necessary for any instance of the type. | ||
|
|
||
| The ability of a class or struct in C# to have more than one constructor provides for generality, but at the expense of some tedium in the declaration syntax, because the constructor input and the class state need to be cleanly separated. Primary constructors put the parameters of one constructor in scope for the whole class or struct to be used for initialization or directly as object state. The trade-off is that any other constructors must call through the primary constructor. |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The paragraph uses passive voice ("provides for generality") and complex phrasing that doesn't follow the conversational, active voice style required by the documentation guidelines. The text should be rewritten in active voice with simpler, more direct language. Consider rephrasing to use "you" and present tense with a conversational tone.
|
|
||
| This rule flags classes that can use a [primary constructor](../../../csharp/programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) instead of a separate constructor definition. You define a primary constructor by placing any constructor parameters in parentheses following the type name. A primary constructor indicates that these parameters are necessary for any instance of the type. | ||
|
|
||
| The ability of a class or struct in C# to have more than one constructor provides for generality, but at the expense of some tedium in the declaration syntax, because the constructor input and the class state need to be cleanly separated. Primary constructors put the parameters of one constructor in scope for the whole class or struct to be used for initialization or directly as object state. The trade-off is that any other constructors must call through the primary constructor. |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Markdown writing style guidelines, complex sentences should be broken up for clarity. This sentence contains multiple clauses that make it difficult to scan and understand. Break this into shorter, clearer sentences.
|
|
||
| This rule flags classes that can use a [primary constructor](../../../csharp/programming-guide/classes-and-structs/instance-constructors.md#primary-constructors) instead of a separate constructor definition. You define a primary constructor by placing any constructor parameters in parentheses following the type name. A primary constructor indicates that these parameters are necessary for any instance of the type. | ||
|
|
||
| The ability of a class or struct in C# to have more than one constructor provides for generality, but at the expense of some tedium in the declaration syntax, because the constructor input and the class state need to be cleanly separated. Primary constructors put the parameters of one constructor in scope for the whole class or struct to be used for initialization or directly as object state. The trade-off is that any other constructors must call through the primary constructor. |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase "need to be cleanly separated" is imprecise and doesn't follow the guideline to use specific, concrete language. What does "cleanly separated" mean in this context? Use more precise technical terminology.
Explain the benefits and trade-offs of using primary constructors in C#.
Internal previews