开发者

In VB.net, how can two read-only properties with no parameters overload eachother?

I've noticed that a class can "overload" a read-only property of its parent class, even though this isn't allowed within a class. I don't understand why this is allowed or what (if anything) it accomplishes.

Class myClass
    ReadOnly Property SomeProp As Integer
        Get
            Return 50
        End Get
    End Property
End Class

Class mySubClass
    Inherits myClass    
    Overloads ReadOnly Property SomeProp As Integer
        Ge开发者_Python百科t
            Return 12
        End Get
    End Property
End Class

The signature of mySubClass.SomeProp is identical to myClass.Prop—how can the former overload the latter?

In practice this seems to function just like Shadows, is that true?


In essence yes, with the overload you'll have myClass::SomeProp and mySubClass::SomeProp

Given an instance of mySubClass, calls to SomeProp will resolve to mySubClass::SomeProp as the best match. However since it's Overloads and not Shadows, something like

Readonly Property SomeProp(x as Integer) as integer)
  Get
    Return 13
  End Get
End Property

won't compile since it lacks the Overloads decorator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜