Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 3, 2025

The documentation incorrectly stated that there is "only one copy" of each static field, which is misleading for generic types. For generic types, each closed generic type (e.g., MyClass<int> vs MyClass<string>) has its own separate storage location for static fields.

Changes Made

Updated three documentation files to add clarifying language about static field storage in generic types:

  • docs/csharp/language-reference/keywords/static.md - Added clarification after the statement about "only one copy of each static field"
  • docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md - Added clarification in the "Static Members" section
  • docs/csharp/misc/cs1914.md - Added clarification in the compiler error documentation

Example

class MyClass<T>
{
    static int count;
}

// These are separate storage locations:
MyClass<int>.count = 1;
MyClass<string>.count = 2;
// MyClass<int>.count is still 1, MyClass<string>.count is 2

The changes are minimal and surgical, preserving the existing content while adding the necessary clarification. The terminology continues to use "static field" as recommended by @BillWagner, avoiding the ambiguous "class field" term.

Fixes #22805.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/keywords/static.md docs/csharp/language-reference/keywords/static
docs/csharp/misc/cs1914.md docs/csharp/misc/cs1914
docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md docs/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Jul 3, 2025
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] 'class field' might be more in place than 'static field' Fix static field documentation to clarify storage behavior for generic types Jul 3, 2025
Copilot finished work on behalf of BillWagner July 3, 2025 16:17
@Copilot Copilot AI requested a review from BillWagner July 3, 2025 16:17
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot finished work on behalf of jkotas July 3, 2025 21:19
@Copilot Copilot AI requested a review from jkotas July 3, 2025 21:19
@BillWagner BillWagner marked this pull request as ready for review July 7, 2025 17:58
@BillWagner BillWagner requested a review from a team as a code owner July 7, 2025 17:58
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 LGTM after responding to @jkotas 's feedback.

@BillWagner BillWagner requested review from IEvangelist and a team July 7, 2025 17:59
@BillWagner BillWagner enabled auto-merge (squash) July 8, 2025 14:02
@BillWagner BillWagner merged commit fc05938 into main Jul 8, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-22805 branch July 8, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csharp-errors-warnings/subsvc dotnet-csharp/svc fundamentals/subsvc lang-reference/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'class field' might be more in place than 'static field'
4 participants