简体   繁体   English

我可以使用什么作为List的通用,所以我可以在vb.net中更改列表中的类型

[英]what can i use as a generic of List so i can change the type within the list in vb.net

so i currently have 所以我现在有

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

but I cannot figure out what to use as an interface . 但我无法弄清楚用什么作为界面。 so that the method getprivateList is able to return both variations of list, depending on the class of implementation. 因此getprivateList方法能够返回列表的两个变体,具体取决于实现类。

You could return IEnumerable , ICollection , or IList . 您可以返回IEnumerableICollectionIList IEnumerable has the least functionality and IList has the most. 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

Alternatively, you could define your base class as a generic class which takes the type of list item: 或者,您可以将基类定义为采用列表项类型的泛型类:

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.

相关问题 如何创建将作为参数传递的泛型类型的列表(VB.Net) - How can I create a list of a generic type that will be passed as a parameter (VB.Net) 我如何在vb.net中更改字符串名称列表 - How can i change a list of string name In vb.net 如何将自定义类的常规列表绑定到datagridview并仅在VB.NET中显示特定属性? - How can i bind a generic List of custom classes to a datagridview and only show specific properties in VB.NET? 如何创建资源列表,以便可以使用索引引用元素? -VB.NET - How can i create a list of my resources so i can refer to an element using index? - VB.NET vb.net:如何查看元素的值是否在列表中 - vb.net: How can I see if the value of an element is in a list 我可以用什么代替vb.net中的isnumeric - What can I use instead of isnumeric in vb.net VB.Net - 我如何获得List中包含的对象的类型 - VB.Net - how can i get the type of the object contained in an List 我可以将它更改为 vb.net list(of Date) to Date() 或 ArrayList(of Date) to Date()? - Can I change it to vb.net list(of Date) to Date() OR ArrayList(of Date) to Date()? VB.NET List(Of T)-我可以用它保存几种类型的项目吗? - VB.NET List(Of T) - Can I use it to hold items of several types? 我可以在lamba表达式中包含泛型类型参数吗? (VB.NET 2010) - Can I include a Generic type parameter in a lamba expression? (VB.NET 2010)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM