Hashtable: setting a value?

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

    #1

    Hashtable: setting a value?

    How do you reset a value for an existing key in a hashtable? I need to
    create a collection and compare the values with another collection: when
    certain parameters are met then I need to reset the value of certain
    elelments in the first collection.

    I would have thought that the Hashtable.Item property would do the
    trick, as MSDN defines it as "Gets or sets the value associated with the
    specified key". But the actual documentation is so obtuse it's just silly:

    http://msdn.microsoft.com/library/de...sitemtopic.asp

    Thanks in advance.
  • Jon Skeet [C# MVP]

    #2
    Re: Hashtable: setting a value?

    BCM <BCM@email.none > wrote:[color=blue]
    > How do you reset a value for an existing key in a hashtable? I need to
    > create a collection and compare the values with another collection: when
    > certain parameters are met then I need to reset the value of certain
    > elelments in the first collection.
    >
    > I would have thought that the Hashtable.Item property would do the
    > trick, as MSDN defines it as "Gets or sets the value associated with the
    > specified key". But the actual documentation is so obtuse it's just silly:
    >
    > http://msdn.microsoft.com/library/de...ary/en-us/cpre
    > f/html/frlrfsystemcoll ectionshashtabl eclassitemtopic .asp[/color]

    In what way is it obtuse?

    <quote>
    When setting this property, if the specified key already exists in the
    Hashtable, the value is replaced; otherwise, a new element is created
    </quote>

    Seems pretty clear to me.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • BCM

      #3
      Re: Hashtable: setting a value?

      It's obutuse primarily because the Item property doesn't appear as an
      option using intellisense.

      Jon Skeet [C# MVP] wrote:
      [color=blue]
      > BCM <BCM@email.none > wrote:
      >[color=green]
      >>How do you reset a value for an existing key in a hashtable? I need to
      >>create a collection and compare the values with another collection: when
      >>certain parameters are met then I need to reset the value of certain
      >>elelments in the first collection.
      >>
      >>I would have thought that the Hashtable.Item property would do the
      >>trick, as MSDN defines it as "Gets or sets the value associated with the
      >>specified key". But the actual documentation is so obtuse it's just silly:
      >>
      >>http://msdn.microsoft.com/library/de...ary/en-us/cpre
      >>f/html/frlrfsystemcoll ectionshashtabl eclassitemtopic .asp[/color]
      >
      >
      > In what way is it obtuse?
      >
      > <quote>
      > When setting this property, if the specified key already exists in the
      > Hashtable, the value is replaced; otherwise, a new element is created
      > </quote>
      >
      > Seems pretty clear to me.
      >[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Hashtable: setting a value?

        BCM <BCM@email.none > wrote:[color=blue]
        > It's obutuse primarily because the Item property doesn't appear as an
        > option using intellisense.[/color]

        And yet the documentation clearly states:

        <quote>
        In C#, this property is the indexer for the Hashtable class.
        </quote>

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • BCM

          #5
          Re: Hashtable: setting a value?

          Ahhh... so the notation is something like...

          ht[key] = DateTime.Now;

          OK. Thanks.

          Jon Skeet [C# MVP] wrote:
          [color=blue]
          > BCM <BCM@email.none > wrote:
          >[color=green]
          >>It's obutuse primarily because the Item property doesn't appear as an
          >>option using intellisense.[/color]
          >
          >
          > And yet the documentation clearly states:
          >
          > <quote>
          > In C#, this property is the indexer for the Hashtable class.
          > </quote>
          >[/color]

          Comment

          Working...