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看到了光.
原文链接:https://www.f2er.com/vb/255122.html所以,在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.