在VB.net中重载与重写

Other1和Other2 Class的上一个属性的行为差异是什么?

注意,除了返回类型的ovrloaded的Other2的上一个属性,因为bean更改为Other2,而它保留为Other1的Base.

Public Class Base
    Private _PrevIoUs as Base

    Protected Overridable ReadOnly Property PrevIoUs As Base
         Get
             Return _PrevIoUs 
         End Get
    End Property

    Public Sub New(PrevIoUs as Base)
         _PrevIoUs = PrevIoUs 
    End Sub
End Class

Public Class Other1
    Inherits Base
    Private _Parent as SomeType

    Protected Overrides ReadOnly Property PrevIoUs As Base
         Get
             Return _Parent.PrevIoUs.something
         End Get
    End Property

    Public Sub New(Parent as SomeType)
        MyBase.New(nothing)
        _Parent = Parent 
    End Sub
End Class

Public Class Other2
    Inherits Base
    Private _Parent as SomeType

    Protected Overloads ReadOnly Property PrevIoUs As Other2
         Get
             Return _Parent.PrevIoUs.something
         End Get
    End Property

    Public Sub New(Parent as SomeType)
        MyBase.New(nothing)
        _Parent = Parent 
    End Sub
End Class
在对我的评论 Jim Wooley’s answer之后,“看起来像阴影超载的属性”.我在 this article看到了光.

所以,在Other2类中的重载比一般更像是覆盖.文章中的comments之一是特别有启发性的:

The confusion arises because the keyword “Overloads” isn’t what a C# programmer considers an overload in the Traditional OO sense. It’s a type of hiding that is specific to VB.Net. You can actually swap the keyword SHADOWS with OVERLOADS in most cases,and the behavior is the same. The difference is when you have a base class with multiple overloaded method signatures. If you declare a method in a subclass with a matching name,and the SHADOWS keyword,it will hide EVERY overload of that method in the base class. If you use the OVERLOADS keyword instead,it will only hide the base class method with an identical signature.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...