CS1540 - accessing base class protected member from child class's nested class #6598
Unanswered
TahirAhmadov
asked this question in
General
Replies: 1 comment
-
The wording is:
the problem here is, that C could be something else than a C or D it could be E which inherits from C, too. You could change public void Bar()
{
if (this._owner is D d)
{
d._x = 1;
}
} Or you could make |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The following code: SharpLab
Produces
error CS1540: Cannot access protected member 'C._x' via a qualifier of type 'C'; the qualifier must be of type 'D.Child' (or derived from it)
Shouldn't this be legal? After all,
Child
is nested inD
, andD
is a subclass ofC
, soC
protected members are visible toD
and by extension to everything nested inD
. Am I missing anything?Beta Was this translation helpful? Give feedback.
All reactions