-
Notifications
You must be signed in to change notification settings - Fork 6k
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
base: main
Are you sure you want to change the base?
Conversation
…ed examples and comparison table Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
There was a problem hiding this 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>
There was a problem hiding this 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)] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@copilot Can you start working on this again? |
@copilot Can you start working on this again? |
@copilot Can you start working on this again? |
The documentation for
protected
,private protected
, andprotected 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
myValue
as the member name for consistencyAssembly1.cs
,Assembly2.cs
) across all examplesprotected.md
to use inline examples instead of external code referencesEnhanced Explanations
New Comparison Table
Added a clear comparison table in
private-protected.md
:protected
protected internal
private protected
Usage Guidelines
Added clear guidance on when to use each modifier:
protected
when you want derived classes in any assembly to access the memberprotected internal
when you want the most permissive accessprivate protected
when you want the most restrictive protected accessThese 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