Skip to content

Fix static field documentation to clarify storage behavior for generic types #47091

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
@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
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
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'
3 participants