Get properties from derived class in base class

前端 未结 7 2231
面向向阳花
面向向阳花 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:10

    Another way to solve this issue by create virtual property in base class and override it to derived class.

    public class Employee
    {
        public virtual string Name {get; set;}
    }
    
    public class GeneralStaff
    {
        public override string Name {get; set;}
    }
    
    class Program
    {
            static void Main(string[] args)
            {
                Employee emp = new GeneralStaff();
                emp.Name = "Abc Xyz";
                //---- More code follows----            
            }
    }
    

提交回复
热议问题