collection question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Buchanan

    #1

    collection question

    i'm sure this question has been asked a number of times, but i can't seem to
    located the answer...

    what is the recommend way to build a custom collection in vb 2005, so that i
    can have have Item property that returns an instance of a class by a key
    value? for example, Teams("sonics") .Wins.Value=10

    should i be using a sortedlist rather than the collectionbase? i'd rather
    not use the compatibility features of the
    Microsoft.Visua lBasic namespace.

    thanks.

    craig buchanan


  • Craig Buchanan

    #2
    Re: collection question

    looks like i want to use the DictionaryBase

    "Craig Buchanan" <someone@micros oft.com> wrote in message
    news:OnCOpEiYGH A.4760@TK2MSFTN GP03.phx.gbl...[color=blue]
    > i'm sure this question has been asked a number of times, but i can't seem
    > to located the answer...
    >
    > what is the recommend way to build a custom collection in vb 2005, so that
    > i can have have Item property that returns an instance of a class by a key
    > value? for example, Teams("sonics") .Wins.Value=10
    >
    > should i be using a sortedlist rather than the collectionbase? i'd rather
    > not use the compatibility features of the
    > Microsoft.Visua lBasic namespace.
    >
    > thanks.
    >
    > craig buchanan
    >[/color]


    Comment

    • Brian Gideon

      #3
      Re: collection question

      Craig,

      Try the Dictionary generic class. You can strongly type it to accept
      Team values and String keys.

      <http://msdn2.microsoft .com/en-us/library/xfhwa508(VS.80) .aspx>

      Brian

      Craig Buchanan wrote:[color=blue]
      > i'm sure this question has been asked a number of times, but i can't seem to
      > located the answer...
      >
      > what is the recommend way to build a custom collection in vb 2005, so that i
      > can have have Item property that returns an instance of a class by a key
      > value? for example, Teams("sonics") .Wins.Value=10
      >
      > should i be using a sortedlist rather than the collectionbase? i'd rather
      > not use the compatibility features of the
      > Microsoft.Visua lBasic namespace.
      >
      > thanks.
      >
      > craig buchanan[/color]

      Comment

      • zacks@construction-imaging.com

        #4
        Re: collection question


        Brian Gideon wrote:[color=blue]
        > Craig,
        >
        > Try the Dictionary generic class. You can strongly type it to accept
        > Team values and String keys.
        >
        > <http://msdn2.microsoft .com/en-us/library/xfhwa508(VS.80) .aspx>[/color]

        What's the difference between using the Dictionary class and using a
        HashTable (which is how the Dictionary class is implemented)?

        Comment

        • Brian Gideon

          #5
          Re: collection question

          Dictionary is generic so you can specify what types are acceptable for
          the key and value. Hashtable accepts any object. The advantage of
          using the Dictionary is that you get compile time type checking and
          faster performance since value types don't have to be boxed/unboxed.
          Of course, Dictionary is only available in .NET 2.0.

          zacks@construct ion-imaging.com wrote:[color=blue]
          > Brian Gideon wrote:[color=green]
          > > Craig,
          > >
          > > Try the Dictionary generic class. You can strongly type it to accept
          > > Team values and String keys.
          > >
          > > <http://msdn2.microsoft .com/en-us/library/xfhwa508(VS.80) .aspx>[/color]
          >
          > What's the difference between using the Dictionary class and using a
          > HashTable (which is how the Dictionary class is implemented)?[/color]

          Comment

          • Chris Dunaway

            #6
            Re: collection question

            Why go through the trouble of building your own class when, as Brian
            says, you can use a Dictionary(Of T) generic to do the same thing?

            Comment

            Working...