Hashtable object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PAzevedo@gmail.com

    #1

    Hashtable object

    If i can use keys of different types on an Hashtable object, what's
    stopping me from putting all my values on the same Hashtable?

  • Bruce Wood

    #2
    Re: Hashtable object


    PAzevedo@gmail. com wrote:
    If i can use keys of different types on an Hashtable object, what's
    stopping me from putting all my values on the same Hashtable?
    So long as all of the keys are comparable using Equals(), there are no
    duplicates across the various types of keys, and you can tell which
    type of value you're getting back for a given key... nothing at all.

    Kinda messy and difficult to understand, though.

    Comment

    • apathetic

      #3
      Re: Hashtable object

      PAzevedo@gmail. com wrote:
      If i can use keys of different types on an Hashtable object, what's
      stopping me from putting all my values on the same Hashtable?
      It's inefficient and very difficult to maintain. You are talking about
      mixing types of objects in a collection, so your consuming code will
      have to test what type of object it has in order to cast it and do
      anything useful. More generally, using the old style collections (not
      typesafe), you risk finding errors at runtime that the compiler cannot
      possibly catch.

      apathetic

      Comment

      • Arne Vajhøj

        #4
        Re: Hashtable object

        PAzevedo@gmail. com wrote:
        If i can use keys of different types on an Hashtable object, what's
        stopping me from putting all my values on the same Hashtable?
        Nothing.

        If your goal is to create the most unreadable code, then it
        is even a good idea !

        But ...

        :-)

        Arne

        Comment

        • Peter Bromberg [C# MVP]

          #5
          RE: Hashtable object

          That, I think, was the whole point of getting away from object which needs to
          be casted to your type (an expensive operation) vs. Generics, where you can
          have the equivalent collection such as List<Twhich is strongly typed and
          requires no casting. Did I say it was an expensive operation?
          Of course, if you are seeking typecast bipolar disorder, then-- whatever
          floats yer boat!
          Peter

          --
          Co-founder, Eggheadcafe.com developer portal:

          UnBlog:





          "PAzevedo@gmail .com" wrote:
          If i can use keys of different types on an Hashtable object, what's
          stopping me from putting all my values on the same Hashtable?
          >
          >

          Comment

          Working...