virtual properties

前端 未结 7 1437
迷失自我
迷失自我 2020-12-14 00:00

I have used and learned only virtual methods of the base class without any knowledge of virtual properties used as

class A
{
   public virtual ICollection<         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 00:37

    Properties are actually specials cases of Getter and Setter methods. So they are like combinations of Getter and Setter methods as shown below:

    private string _name;
    
    public string GetName()
    {
       return _name;
    }
    
    public void SetName(string value)
    {
       this._name = value;
    }
    

    So virtual keyword is same for properties as well which means it is overrideable by the child classes and initial implementation can be changed.

提交回复
热议问题