[英]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.