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

后端 未结 7 1136
轻奢々
轻奢々 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:32

    As you are inheriting from MyBase, you can access all fields/properties/methods from it marked as "protected" using the "base" keyword.

    public class MyBase
    {
        protected object PropertyOfBase { get; set; }
    }
    
    public class MyType : MyBase
    {
        void MyMethod()
        {
            object p =  base.PropertyOfBase;
        }
    }
    

提交回复
热议问题