Is there a way to reach a `protected` member of another object from a derived type?

后端 未结 7 1065
轻奢々
轻奢々 2020-11-30 13:41
class MyBase
{
    protected object PropertyOfBase { get; set; }
}

class MyType : MyBase
{
    void MyMethod(MyBase parameter)
    {
        // I am looking for:
           


        
相关标签:
7条回答
  • 2020-11-30 14:35

    A protected property is only accessible to an instance of a derived class, not to instances of derived classes.

    There is a difference and it does make sense, protected members should not give up their value to any other instance, even an instance derived from the same type.

    (Edited, got myself a bit tongue tied!)

    0 讨论(0)
提交回复
热议问题