[英]How can I create a list of a generic type that will be passed as a parameter (VB.Net)
[英]what can i use as a generic of List so i can change the type within the list in vb.net
所以我现在有
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方法能够返回列表的两个变体,具体取决于实现类。
您可以返回IEnumerable
, ICollection
或IList
。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.