0

所以我目前有

class general
private list as List(Of string) 

public overridable function getprivateList as <not sure what to put>
    return list
end function
end class

class specific inherits general
private list as List(Of listofstrings)

end class

但我无法弄清楚将什么用作界面。因此 getprivateList 方法能够返回列表的两种变体,具体取决于实现的类。

4

1 回答 1

2

您可以返回IEnumerable,ICollectionIList. IEnumerable功能最少,功能IList最多。

Class General
    Private list As List(Of String) 

    Public Overridable Function GetPrivateList() As IList
        Return list
    End Function
End Class

Class Specific 
    Inherits General
    Private list As List(Of Integer)
End Class

或者,您可以将基类定义为采用列表项类型的泛型类:

Class General(Of T)
    Private list As List(Of T) 

    Public Overridable Function GetPrivateList() As List(Of T)
        Return list
    End Function
End Class

Class Specific 
    Inherits General(Of Integer)
End Class
于 2012-09-18T12:01:26.330 回答