Open
Clarify private constants use PascalCase; fix public field casing in const example#54728
Conversation
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
adegeo
reviewed
Jul 9, 2026
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 (`_`). |
Contributor
There was a problem hiding this comment.
@copilot Move the "Private non-constant.." up so it's next to the other non-constant.
Contributor
Author
There was a problem hiding this comment.
Done — moved the "Private non-constant instance fields" bullet up to immediately follow the camelCase non-constant bullet in d0d8c02's successor commit.
Contributor
There was a problem hiding this comment.
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
_camelCaseapplies to private non-constant fields, while constants use PascalCase even whenprivateorinternal. - Adds a NOTE callout example demonstrating private constant vs. private field naming.
- Fixes
x/y→X/Yin theconstkeyword 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The identifier names page didn't explicitly resolve whether private constants should follow the
_camelCaserule for private fields or the PascalCase rule for constants. Theconstkeyword example also showed public fields namedx/yinstead of the PascalCaseX/Y.Changes
identifier-names.mdUpdated camelCase and PascalCase bullets to explicitly scope each rule:
_camelCaseapplies to private non-constant fields; PascalCase applies to constants regardless of access modifierAdded a
[!NOTE]callout in the Camel case section with a side-by-side example:csrefKeywordsModifiers.cs(snippet 5) — Renamed public fieldsx/y→X/Yand updated all usages and the output comment to matchInternal previews