Get properties from derived class in base class

前端 未结 7 2241
面向向阳花
面向向阳花 2021-02-09 07:02

How do I get properties from derived class in base class?

Base class:

public abstract class BaseModel {
    protected static readonly Dictionary

        
7条回答
  •  情话喂你
    2021-02-09 07:21

    If you require that a derived class must implement a method or property, you should introduce that method or property into the base class as an abstract declaration.

    For example, for your Name property, you would add to the base class:

    public abstract string Name { get; set; }
    

    Then any derived classes must implement it, or be abstract classes themselves.

    Once you have added the abstract version of the Name property to the base class, you will be able to access it in the base class anywhere except in the base class's constructor.

提交回复
热议问题