Skip to content

Commit 60df0ef

Browse files
CopilotBillWagner
andauthored
Fix incorrect protected access modifier documentation and code comments (#47038)
* Initial plan * Fix incorrect information about protected access modifier Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
1 parent 16a23f6 commit 60df0ef

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/csharp/language-reference/keywords/protected.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A protected member of a base class is accessible in a derived class only if the
2626

2727
[!code-csharp[csrefKeywordsModifiers#11](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsModifiers/CS/csrefKeywordsModifiers.cs#11)]
2828

29-
The statement `a.x = 10` generates an error because it is made within the static method Main, and not an instance of class B.
29+
The statement `a.x = 10` generates an error because it accesses the protected member through a base class reference (`a` is of type `A`). Protected members can only be accessed through the derived class type or types derived from it.
3030

3131
Struct members cannot be protected because the struct cannot be inherited.
3232

samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsModifiers/CS/csrefKeywordsModifiers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ static void Main()
345345
var a = new A();
346346
var b = new B();
347347

348-
// Error CS1540, because x can only be accessed by
349-
// classes derived from A.
348+
// Error CS1540, because x can only be accessed through
349+
// the derived class type, not through the base class type.
350350
// a.x = 10;
351351

352352
// OK, because this class derives from A.

0 commit comments

Comments
 (0)