Do adding properties to an interface prevent creating private/protected “set” in derived types?

后端 未结 2 608
长情又很酷
长情又很酷 2020-12-16 11:53

Edit: It turns out I missed something obvious, but I\'m going to leave the question open in case someone else makes the same obvious mistake. Thanks to

2条回答
  •  执念已碎
    2020-12-16 12:56

    This is perfectly legal. You don't need the override keyword (in fact it wouldn't compile) but there's nothing stopping you from doing this:

    interface IField
    {
        bool IsValid { get; }
    }
    
    class Field : IField
    {
        public bool IsValid { get; protected set; }
    }
    

提交回复
热议问题