在VB.net中,两个没有参数的只读属性如何互相重载?
我注意到一个类可以“重载”其父类的只读属性,即使在类中不允许这样做。我不明白为什么允许这样做或者它能实现什么(如果有的话)。
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
Get
Return 12
End Get
End Property
End Class
mySubClass.SomeProp
的签名与 myClass.Prop
相同 - 前者如何重载后者?
实际上,这似乎就像 Shadows
一样起作用,是真的吗?
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
Get
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本质上是的,通过重载,您将拥有 myClass::SomeProp 和 mySubClass::SomeProp
给定 mySubClass 的实例,对 SomeProp 的调用将解析为 mySubClass::SomeProp 作为最佳匹配。然而,由于它是重载而不是阴影,因此类似的东西
不会编译,因为它缺少重载装饰器。
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
won't compile since it lacks the Overloads decorator.