Override abstract readonly property to read/write property

前端 未结 5 1311
死守一世寂寞
死守一世寂寞 2020-12-10 11:14

I would like to only force the implementation of a C# getter on a given property from a base abstract class. Derived classes might, if they want, also provide a setter for t

5条回答
  •  隐瞒了意图╮
    2020-12-10 11:48

    What about something like:

    public abstract class Base
    {
        public virtual int Property
        {
            get { return this.GetProperty(); }
            set { }
        }
    
        protected abstract int GetProperty();
    }
    

提交回复
热议问题