当前位置 : 主页 > 编程语言 > c语言 >

为什么在.net中读取/写入属性不能覆盖readonly属性?

来源:互联网 收集:自由互联 发布时间:2021-06-24
从概念上讲,似乎派生类应该能够使用读写属性覆盖readonly属性.为什么这不可能? Public Class Base Protected _name As String Public Overridable ReadOnly Property Name() As String Get return _name End Get End Proper
从概念上讲,似乎派生类应该能够使用读写属性覆盖readonly属性.为什么这不可能?

Public Class Base

    Protected _name As String
    Public Overridable ReadOnly Property Name() As String
        Get
            return _name
        End Get
    End Property

End Class

Public Class Derived
    Inherits Base

    Public Overrides Property Name() As String
        Get
            Return MyBase.Name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

End Class
我认为这清楚地解释了它.

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

网友评论