Skip to content

Wrong information in first protected example #17445

Closed
@v-kydela

Description

@v-kydela

There seems to be some incorrect information in the first example.

        // Error CS1540, because x can only be accessed by
        // classes derived from A.
        // a.x = 10; 

B is derived from A, so that's not the reason why x cannot be accessed. B can only access x through a reference that is assignable to type B (meaning B or derived from B).

Another incorrect reason for the error is given under the example:

The statement a.x = 10 generates an error because it is made within the static method Main, and not an instance of class B.

It makes no difference whether Main is a static method or an instance method. You can try removing the static modifier from Main and observe that the same error is still there. Again, the reason for the error is because B is trying to access x through an instance of A, and not because Main is static or because "x can only be accessed by classes derived from A."


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 446785

Metadata

Metadata

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-csharp/svcfundamentals/subsvcin-prThis issue will be closed (fixed) by an active pull request.lang-reference/subsvcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions