Jump to content
Xtreme .Net Talk

VB6 -> VB.Net collection classes


Recommended Posts

Guest Imogen
Posted

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 VB's collection class

 

object: my own custom object.

 

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

 

thanks Imogen

  • *Gurus*
Posted

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.

  • 3 months later...
  • *Experts*
Posted

To make a type safe collection, inherit from the DictionaryBase collection and overload the properties Item, Add and Contains e.g.:

 

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

Printer Monitor for .NET? - see Merrion Computing Ltd for details

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...