1

Possible Duplicate:
Why is it impossible to override a getter-only property and add a setter?

Let's say that I got the following interfaces:

public interface IMessage
{
    bool KeepAlive { get; }
}

public interface IRequest : IMessage
{
    bool KeepAlive { get; }
}

The problem is that I want the IReponse interface to have a setter:

public interface IReponse : IMessage
{
    bool KeepAlive { get; set; }
}
  1. Why isn't that allowed?
  2. What kind of problems can I get if I do new bool KeepAlive { get; set; }.

Update:

I read the other question and it says that it's not expected that the property will change. I do not agree. Let's take for instance Socket.Connected property. It has only a getter, but it CAN be changed. What a readonly property says is that the property can only be changed from within the implementation.

Community
  • 1
  • 1
jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • Have a look at this question/answer, although it focuses mainly VB.NET: http://stackoverflow.com/questions/554369/overriding-readonly-property-in-a-subclass-to-make-it-read-write-vb-net/554396#554396 – Tim Schmelter Jun 17 '11 at 08:01
  • I agree with jgauffin's update. A get-only property does not imply it will not change. – Steven Jun 17 '11 at 16:39

0 Answers0