Link to home
Start Free TrialLog in
Avatar of crestsolutions
crestsolutions

asked on

Collection Classes in VB.NET

I want a collection class to be a property of another class in VB.NET. How do I implement this? What I am asking is analagous to a recordsets and fields in VB6. I want to be able to create an instance of one class via another class. e.g.

dim x as new recordset
dim y as new field

set y = x.fields.add("Field1", ...................)


Avatar of arif_eqbal
arif_eqbal

Create a class like....


Public Class Class1
    'Normal properties
    Public MyProperty As String
   
    'a Collection variable
    Public MyCollection As Collection = New Collection

    Public Sub MyMethod()
       'Normal methods
    End Sub

End Class


Then you can use the class as

Dim objClass1 as Class1=New Class1

objClass1.MyCollection.Add("Item","Key")

'This is the simplest example, you might add some Abstraction in your actual code
'And not have All Public variables/collections etc.
ASKER CERTIFIED SOLUTION
Avatar of arif_eqbal
arif_eqbal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial