Skip to content

Add naming conventions for primary constructor parameters #48009

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

Merged
merged 4 commits into from
Aug 20, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 19, 2025

This PR adds comprehensive naming conventions for primary constructor parameters to the C# identifier naming documentation, addressing a gap identified in issue #42295.

Changes Made

Documentation Updates:

  • Added new "Primary constructor parameters" subsection to the "Camel case" section in identifier-names.md
  • Clarified the distinction between naming conventions for different type declarations:
    • Class and struct types: Use camelCase (consistent with method parameters)
    • Record types: Use PascalCase (as parameters become public properties)

Code Examples:

  • Created new code snippets demonstrating correct naming patterns:
    // Class primary constructor - camelCase
    public class DataService(IWorkerQueue workerQueue, ILogger logger)
    
    // Struct primary constructor - camelCase  
    public struct Point(double x, double y)
    
    // Record primary constructor - PascalCase
    public record Person(string FirstName, string LastName);

Validation:

  • All code examples compile and run successfully
  • Existing repository examples already follow the documented conventions
  • Documentation passes markdownlint validation

This addresses the original question about whether to use Entity(Dependency dependency) vs Entity(Dependency _dependency) - the answer is the former (camelCase without underscore prefix) for regular classes and structs.

Fixes #42295.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/csharp/fundamentals/coding-style/identifier-names.md C# identifier naming rules and conventions

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Are there any naming rules for primary constructors? Add naming conventions for primary constructor parameters Aug 19, 2025
@Copilot Copilot AI requested a review from BillWagner August 19, 2025 19:32
Copilot finished work on behalf of BillWagner August 19, 2025 19:32
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review, once my suggestions are merged.

@BillWagner BillWagner requested a review from adegeo August 20, 2025 14:08
@BillWagner BillWagner marked this pull request as ready for review August 20, 2025 14:08
@BillWagner BillWagner requested a review from a team as a code owner August 20, 2025 14:08
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
@BillWagner BillWagner enabled auto-merge (squash) August 20, 2025 20:18
@BillWagner BillWagner merged commit c6c53f1 into main Aug 20, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-42295 branch August 20, 2025 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Are there any naming rules for primary constructors?
3 participants