No Hashtable.Get(key) method?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Pöpping

    No Hashtable.Get(key) method?

    Hello,

    I´m trying to implement a "reverse index table" using a hashtable.

    But in the hashtable class i cannot find any get-Method.
    The Java class of hashtable for example provides a method:
    get(Object key)

    Isn´t there any method in C# too?

    If not... how to retrieve a value of a specific key?

    And another question...

    As I wrote, I have to implement a reverse index table.

    This means that I have a class called "Document" and keys as int values.
    I have to assign several Documents to one key. How would you do that to
    get a most performant way?

    My plan was to use a Hashtable in combination with a List.
    Means I have int as keys for my Hashtable and putting my Document
    objects into a List which I put into the Hashtable as value to a
    specific key.

    Is this a good idea?
    I thought it very performant, because you can search very fast in a
    Hashtable.



    Regards,

    Martin
  • Arne Vajhøj

    #2
    Re: No Hashtable.Get(k ey) method?

    Martin Pöpping wrote:
    But in the hashtable class i cannot find any get-Method.
    The Java class of hashtable for example provides a method:
    get(Object key)
    >
    Isn´t there any method in C# too?
    C# support the syntax:

    yourhastableobj ect[thekey]

    Arne

    Comment

    • Arne Vajhøj

      #3
      Re: No Hashtable.Get(k ey) method?

      Martin Pöpping wrote:
      This means that I have a class called "Document" and keys as int values.
      I have to assign several Documents to one key. How would you do that to
      get a most performant way?
      >
      My plan was to use a Hashtable in combination with a List.
      Means I have int as keys for my Hashtable and putting my Document
      objects into a List which I put into the Hashtable as value to a
      specific key.
      >
      Is this a good idea?
      I thought it very performant, because you can search very fast in a
      Hashtable.
      Hashtable of ArrayList is a known data structure.

      Sounds OK to me.

      If you are on .NET 2.0 then you should use Dictionary of List
      ofcourse !

      Arne

      Comment

      • Greg Young

        #4
        Re: No Hashtable.Get(k ey) method?

        The default indexor will do this ...


        MyHash[key] or you can use the Item property


        Cheers,

        Greg

        "Martin Pöpping" <martin_p@despa mmed.comwrote in message
        news:ee4gvk$qim $1@newsreader2. netcologne.de.. .
        Hello,
        >
        I´m trying to implement a "reverse index table" using a hashtable.
        >
        But in the hashtable class i cannot find any get-Method.
        The Java class of hashtable for example provides a method:
        get(Object key)
        >
        Isn´t there any method in C# too?
        >
        If not... how to retrieve a value of a specific key?
        >
        And another question...
        >
        As I wrote, I have to implement a reverse index table.
        >
        This means that I have a class called "Document" and keys as int values.
        I have to assign several Documents to one key. How would you do that to
        get a most performant way?
        >
        My plan was to use a Hashtable in combination with a List.
        Means I have int as keys for my Hashtable and putting my Document objects
        into a List which I put into the Hashtable as value to a specific key.
        >
        Is this a good idea?
        I thought it very performant, because you can search very fast in a
        Hashtable.
        >
        >
        >
        Regards,
        >
        Martin

        Comment

        • Bob Powell [MVP]

          #5
          Re: No Hashtable.Get(k ey) method?

          Just use the indexer eg.

          table[key]

          --
          Bob Powell [MVP]
          Visual C#, System.Drawing

          Ramuseco Limited .NET consulting


          Find great Windows Forms articles in Windows Forms Tips and Tricks


          Answer those GDI+ questions with the GDI+ FAQ


          All new articles provide code in C# and VB.NET.
          Subscribe to the RSS feeds provided and never miss a new article.



          "Martin Pöpping" <martin_p@despa mmed.comwrote in message
          news:ee4gvk$qim $1@newsreader2. netcologne.de.. .
          Hello,
          >
          I´m trying to implement a "reverse index table" using a hashtable.
          >
          But in the hashtable class i cannot find any get-Method.
          The Java class of hashtable for example provides a method:
          get(Object key)
          >
          Isn´t there any method in C# too?
          >
          If not... how to retrieve a value of a specific key?
          >
          And another question...
          >
          As I wrote, I have to implement a reverse index table.
          >
          This means that I have a class called "Document" and keys as int values.
          I have to assign several Documents to one key. How would you do that to
          get a most performant way?
          >
          My plan was to use a Hashtable in combination with a List.
          Means I have int as keys for my Hashtable and putting my Document objects
          into a List which I put into the Hashtable as value to a specific key.
          >
          Is this a good idea?
          I thought it very performant, because you can search very fast in a
          Hashtable.
          >
          >
          >
          Regards,
          >
          Martin

          Comment

          Working...