Hashtable.Add Method

   
Hashtable.Add Method

Class

System.Collections.Hashtable

Syntax

   hashtablevariable   .Add(   Key   ,   Value   ) 
Key (required; Object)

The hash table entry's key

Value (required; Object)

The hash table entry's value

Return Value

None

Description

Adds a key/value pair to the hash table

Rules at a Glance

  • Key must be unique or a runtime error occurs.

  • Keys are immutable. Once added, a particular key value cannot be changed during the lifetime of the hash table except by removing it through the Remove or Clear method and then adding it once again.

  • Value need not be unique.

Programming Tips and Gotchas

  • According to the documentation, it is better to build a key from a String object than the Base Class Library's StringBuilder object.

  • The Item property can also be used to add new members to the hash table.

  • To ensure that key is unique when calling the Add method, you can call the ContainsKey method beforehand.

See Also

Hashtable.ContainsKey Method, Hashtable.Item Property

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

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