覆盖接口定义

时间:2011-06-17 07:10:25

标签: .net interface-design

  

可能重复:
  Why is it impossible to override a getter-only property and add a setter?

假设我有以下界面:

public interface IMessage
{
    bool KeepAlive { get; }
}

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

问题是我希望IReponse接口有一个setter:

public interface IReponse : IMessage
{
    bool KeepAlive { get; set; }
}
  1. 为什么不允许这样做?
  2. 如果我做new bool KeepAlive { get; set; },我可以获得什么样的问题。
  3. 更新

    我读了另一个问题,并说它预计不会改变财产。我不同意。我们以Socket.Connected属性为例。它只有一个吸气剂,但它可以改变。 readonly属性所说的是该属性只能从 的实现中更改。

0 个答案:

没有答案
相关问题