Search code examples
vb.neticollection

Generic Icollection Of <T>


I want to Create Object of Icollection of <t>.
My Code is as below.

    Dim oAttributeValues As ICollection(Of AttributeValue)
        = TryCast(AttributeValuePropertyInfo.GetValue(UOMEn, Nothing),
                  ICollection(Of AttributeValue))

Here AttributeValue is my class name. I want this Class generalized Bca I don't know which class of Collection created.


Solution

  • Public Class Collection(Of T As Class)
        Implements ICollection(Of T)
        Implements ICollection
        'Your code
    End Class
    

    Please note that you will have to implement ICollection(Of T) and ICollection interface by yourself. In case you don't want it then you might want to Inherit from System.Collections.ObjectModel.Collection(Of T).

    Public Class Collection(Of T As Class)
        Inherits  System.Collections.ObjectModel.Collection(Of T)    
        'Your code
    End Class