我有一个类似这样的东西:
class Node
{
protected Node Parent
{
get; private set;
}
}
class NodeDerived : Node
{
void SomeMethod()
{
Node parentIterator = this.Parent;
while (parentIterator != null)
{
// ... some logic
parentIterator = parentIterator.Parent; // Here's the error
}
}
}
但是出于某种奇怪的原因,我无法访问parentIterator.Parent
属性:
error CS1540: Cannot access protected member `Node.Parent' via a qualifier of type `Node'. The qualifier must be of type `NodeChild' or derived from it
为什么会发生这种情况呢?顺便提一下,我还发现虽然我可以访问this.Parent
,但是我无法访问((Node) this).Parent
。