VB6 -> VB.Net collection classes

  • Thread starter Thread starter Imogen
  • Start date Start date
I

Imogen

Guest
Hi, when using VB6 I used to use the collection object and put in in a wrapper to facilitate my own collections

e.g.

collection: wrapper around VBs collection class

object: my own custom object.

How do I achieve this in .Net, including exposing the enumeration.

thanks Imogen
 
You have to inherit one of the System.Collections classes and
extend it however you need. But, with all the options available
in the System.Collections namespace, it is hard to believe you
would need to extend one. There is an ArrayList, BitArray,
Dictionary, Hashtable, Queue, SortedList, and Stack. It is a huge
improvement over VB6.
 
To make a type safe collection, inherit from the DictionaryBase collection and overload the properties Item, Add and Contains e.g.:

Code:
Public Class Vehicle
  Public LicencePlate As String \\This is unique...
  Public Make As String
End Class

Public Class VehiclesDictionary
   Inherits Collections.DictionaryBase

   Public Overloads Property Item(ByVal LicencePlate As String) As Vehicle
        Get
            Return CType(dictionary.Item(LicencePlate), Vehicle)
        End Get
        Set (Byval Value As Vehilce)
                dictionary.Item(Value.LicencePlate) = Value
         End Set

   End Property


End Class

Hope this is useful,
Duncan
 
If you just need a strongly-typed collection, you can inherit from CollectionBase.
 
Back
Top