假设我有以下接口:
public interface IMessage
{
bool KeepAlive { get; }
}
public interface IRequest : IMessage
{
bool KeepAlive { get; }
}
问题是我希望IReponse
界面有一个设置器:
public interface IReponse : IMessage
{
bool KeepAlive { get; set; }
}
- 为什么不允许这样做?
- 如果我这样做会遇到什么样的问题
new bool KeepAlive { get; set; }
。
更新:
我读了另一个问题,它说预计财产不会改变。我不同意。让我们以Socket.Connected
财产为例。它只有一个吸气剂,但可以更改。只读属性的意思是该属性只能在实现中更改。