Skip to content

Clarify private constants use PascalCase; fix public field casing in const example#54728

Open
adegeo with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-naming-conventions-private-constants
Open

Clarify private constants use PascalCase; fix public field casing in const example#54728
adegeo with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-naming-conventions-private-constants

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The identifier names page didn't explicitly resolve whether private constants should follow the _camelCase rule for private fields or the PascalCase rule for constants. The const keyword example also showed public fields named x/y instead of the PascalCase X/Y.

Changes

  • identifier-names.md

    • Updated camelCase and PascalCase bullets to explicitly scope each rule: _camelCase applies to private non-constant fields; PascalCase applies to constants regardless of access modifier

    • Added a [!NOTE] callout in the Camel case section with a side-by-side example:

      public class DataService
      {
          private const int MaxRetryCount = 3;   // PascalCase for constants
          private IWorkerQueue _workerQueue;     // _camelCase for non-constant fields
      }
  • csrefKeywordsModifiers.cs (snippet 5) — Renamed public fields x/yX/Y and updated all usages and the output comment to match


Internal previews

📄 File 🔗 Preview link
docs/csharp/fundamentals/coding-style/identifier-names.md docs/csharp/fundamentals/coding-style/identifier-names

Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 17:19
Copilot AI linked an issue Jul 9, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 17:22
Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 17:23
Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 17:23
Copilot AI requested review from Copilot and removed request for Copilot July 9, 2026 17:24
Copilot AI changed the title [WIP] Fix naming conventions for private constants Clarify private constants use PascalCase; fix public field casing in const example Jul 9, 2026
Copilot finished work on behalf of adegeo July 9, 2026 17:25
Copilot AI requested a review from adegeo July 9, 2026 17:25
Comment on lines +40 to +42
- Use camelCase for method arguments, local variables, and private non-constant fields.
- To maintain consistency across all access modifiers, use PascalCase for constant names, both fields and local constants, including `private` and `internal` constants.
- Private non-constant instance fields start with an underscore (`_`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot Move the "Private non-constant.." up so it's next to the other non-constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — moved the "Private non-constant instance fields" bullet up to immediately follow the camelCase non-constant bullet in d0d8c02's successor commit.

@adegeo adegeo marked this pull request as ready for review July 9, 2026 17:31
@adegeo adegeo requested review from a team and BillWagner as code owners July 9, 2026 17:31
Copilot AI review requested due to automatic review settings July 9, 2026 17:31
Copilot finished work on behalf of adegeo July 9, 2026 17:33
Copilot AI requested a review from adegeo July 9, 2026 17:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 clarifies the C# identifier naming guidance around constants (PascalCase regardless of accessibility) and updates a const keyword snippet to use PascalCase for public fields to match the documented convention.

Changes:

  • Clarifies that _camelCase applies to private non-constant fields, while constants use PascalCase even when private or internal.
  • Adds a NOTE callout example demonstrating private constant vs. private field naming.
  • Fixes x/yX/Y in the const keyword snippet and updates related output text.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/csharp/fundamentals/coding-style/identifier-names.md Refines the written naming rules and adds an example callout to disambiguate private constants vs. fields.
docs/csharp/language-reference/keywords/snippets/csrefKeywordsModifiers.cs Updates the const example to use PascalCase for public fields and aligns output text.

Comment on lines +40 to +42
- Use camelCase for method arguments, local variables, and private non-constant fields.
- To maintain consistency across all access modifiers, use PascalCase for constant names, both fields and local constants, including `private` and `internal` constants.
- Private non-constant instance fields start with an underscore (`_`).
Comment on lines +135 to +139
> [!NOTE]
> Private and internal constants use PascalCase (not `_camelCase`) to maintain consistency with constant naming conventions. For example:
>
> ```csharp
> public class DataService
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Naming conventions for private constants

3 participants