Hashtable.Item Property


Hashtable.Item Property

Class

System.Collections.Hashtable

Syntax

     Dim result As Object = hashtableVariable.Item(key) 


key (required; any)

The key with the related value that is to be retrieved

Description

The Item property returns the hashtable value associated with a particular key.

Usage at a Glance

  • Item is the default property of the Hashtable class, so ".Item" is optional. The following two lines are equivalent.

         resultObject = myHashtable.Item("abc")     resultObject = myHashtable("abc") 

  • The Item property can be used to add or update values. The statement:

         myHashtable.Item("abc") = sourceObject 

    either updates the value associated with the key "abc" (if it already exists in the hashtable) or adds it as a new item with the key "abc" (if it does not yet exist in the hashtable).

  • If key does not exist in the hashtable when you attempt to retrieve a value, the Item property returns Nothing.

  • To guard against inadvertently adding a member to the hashtable when you intend to modify an existing value, call the ContainsKey method to test the key.

  • You can also retrieve individual members of the Hashtable object by iterating it using the For Each...Next statement. Each iteration of the loop returns a DictionaryEntry object containing a single key/value pair.

See Also

Hashtable Class




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net