Override abstract readonly property to read/write property

前端 未结 5 1307
死守一世寂寞
死守一世寂寞 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条回答
  •  -上瘾入骨i
    2020-12-10 11:42

    You may do this with a constructor as following;

    public abstract class Base
    {
        public abstract int Property { get; }
    }
    
    
    public class Derived : Base
    {
        public Derived(string Property) : base(Property)
        {
    
        }
    }
    

提交回复
热议问题