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

后端 未结 2 607
长情又很酷
长情又很酷 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:50

    It's possible on interfaces, but not on abstract/virtual properties - you may have these two mixed up.

    0 讨论(0)
  • 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; }
    }
    
    0 讨论(0)
提交回复
热议问题