Skip to content

Improve clarity of protected access modifier documentation with unified examples and comparison table #47117

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

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

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 7, 2025

The documentation for protected, private protected, and protected internal access modifiers was difficult to compare because examples used different member names, inconsistent structures, and lacked clear explanations of the key differences between these related modifiers.

Changes Made

Unified Examples and Naming

  • Standardized all examples to use myValue as the member name for consistency
  • Added consistent assembly file naming (Assembly1.cs, Assembly2.cs) across all examples
  • Updated protected.md to use inline examples instead of external code references

Enhanced Explanations

  • protected: Added cross-assembly example and clarified it works across assemblies for derived classes
  • protected internal: Emphasized it's the most permissive access modifier (any class in same assembly OR derived classes anywhere)
  • private protected: Enhanced explanation that it's the most restrictive protected modifier (only derived classes in same assembly)

New Comparison Table

Added a clear comparison table in private-protected.md:

Access Modifier Same Assembly, Derived Class Same Assembly, Non-derived Class Different Assembly, Derived Class
protected ✔️ ✔️
protected internal ✔️ ✔️ ✔️
private protected ✔️

Usage Guidelines

Added clear guidance on when to use each modifier:

  • Use protected when you want derived classes in any assembly to access the member
  • Use protected internal when you want the most permissive access
  • Use private protected when you want the most restrictive protected access

These changes make it much easier for developers to understand the differences between these three related access modifiers and choose the appropriate one for their needs.

Fixes #23465.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/keywords/private-protected.md docs/csharp/language-reference/keywords/private-protected
docs/csharp/language-reference/keywords/protected-internal.md docs/csharp/language-reference/keywords/protected-internal
docs/csharp/language-reference/keywords/protected.md docs/csharp/language-reference/keywords/protected

…ed examples and comparison table

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] It's not clear difference between protected, private protected, and protected internal from given example. Improve clarity of protected access modifier documentation with unified examples and comparison table Jul 7, 2025
@Copilot Copilot AI requested a review from BillWagner July 7, 2025 18:13
Copilot finished work on behalf of BillWagner July 7, 2025 18:13
@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Jul 8, 2025
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 a good start, but I have a few comments.

…mentation

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI requested a review from BillWagner July 8, 2025 14:21
Copilot finished work on behalf of BillWagner July 8, 2025 14:21
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.

Good work. One more set of changes.

@@ -24,9 +24,11 @@ For a comparison of `protected` with the other access modifiers, see [Accessibil

A protected member of a base class is accessible in a derived class only if the access occurs through the derived class type. For example, consider the following code segment:

[!code-csharp[csrefKeywordsModifiers#11](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsModifiers/CS/csrefKeywordsModifiers.cs#11)]
[!code-csharp[snippet1](~/docs/csharp/language-reference/keywords/snippets/protected/Example1.cs#snippet1)]
Copy link
Member

Choose a reason for hiding this comment

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

Replace all instances of !code-csharp with the ::: directive for code snippets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced all instances of !code-csharp with the ::: directive for code snippets in the protected.md file. Commit: a9c6c61

@BillWagner
Copy link
Member

@copilot Can you start working on this again?

@BillWagner
Copy link
Member

@copilot Can you start working on this again?

@BillWagner
Copy link
Member

@copilot Can you start working on this again?

Copilot finished work on behalf of BillWagner July 10, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc 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.

It's not clear difference between protected, private protected, and protected internal from given example.
2 participants