VB.NET class inherits a base class and implements an interface issue (works in C#)

后端 未结 7 1691
后悔当初
后悔当初 2020-12-09 14:53

I am trying to create a class in VB.NET which inherits a base abstract class and also implements an interface. The interface declares a string property called Description. T

7条回答
  •  春和景丽
    2020-12-09 15:29

    Sorry if I'm late to the party, and apologies too if this functionality has only been introduced in .NET 4, but the following is possible (now)

    Public Interface IFoo
        Property Description() As String
    End Interface
    
    Public MustInherit Class FooBase
        Implements IFoo
    
        Public MustOverride Property Description As String Implements IFoo.Description
    End Class
    
    Public Class MyFoo
        Inherits FooBase
    
        Private _description As String
    
        Public Overrides Property Description As String
            Get
                Return _description
            End Get
            Set(value As String)
                _description = value
            End Set
        End Property
    End Class
    

提交回复
热议问题