Is it possible to override a property and return a derived type in VB.NET?

后端 未结 3 878
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 18:48

Consider the following classes representing an Ordering system:

Public Class OrderBase
    Public MustOverride Property OrderItem as OrderItemBase
End Class
         


        
3条回答
  •  没有蜡笔的小新
    2020-12-20 19:18

    You can't do that - it's changing the signature defined on the base. To do what you are trying to do you need to use generics:

    Public Class OrderBase(Of T As IOrderItem)
        Public ReadOnly Property OrderItems As IList(Of T)
    End Class
    

    My Visual Basic is rusty so hopefully that is accurate...

提交回复
热议问题