Skip to content

Conversation

Copy link
Contributor

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 <[email protected]>
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 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.

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.

@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
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.

A few more comments here.

Copilot AI requested a review from BillWagner July 14, 2025 18:49
Copilot finished work on behalf of BillWagner July 14, 2025 18:49
@BillWagner BillWagner marked this pull request as ready for review July 14, 2025 19:06
@BillWagner BillWagner requested a review from a team as a code owner July 14, 2025 19:06
@BillWagner BillWagner requested a review from IEvangelist July 14, 2025 19:06
@BillWagner
Copy link
Member

The snippets failure is related to a preview feature.

@BillWagner BillWagner merged commit 0e3e811 into main Jul 15, 2025
9 of 10 checks passed
@BillWagner BillWagner deleted the copilot/fix-23465 branch July 15, 2025 18:47
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.

3 participants