ASP Dictionary
Object
The Dictionary object is used to store information in name/value pairs.
Try It Yourself - Examples
Return the number of key/item pairs
Dictionary Object
The Dictionary object is used to store information in name/value pairs (equivalent to keys and items). The Dictionary object appears simpler than an array, yet it is a more satisfying solution for handling associative data.
Comparing Dictionaries and Arrays:
- Keys are used to identify items in the Dictionary object
- You do not need to call ReDim to change the size of the Dictionary object
- When an item is deleted from the Dictionary, the remaining items automatically shift up
- The Dictionary is not multidimensional, whereas arrays are
- The Dictionary comes with more built-in functions than arrays
- The Dictionary performs better than arrays when frequently accessing random elements
- The Dictionary performs better than arrays when locating items based on their content
The following example creates a Dictionary object, adds some key/item pairs to the object, and then retrieves the value of the item with the key "gr":
Properties and methods of the Dictionary object are described below:
Properties
Property | Description |
---|---|
CompareMode | Sets or returns the comparison mode for comparing keys in the Dictionary object. |
Count | Returns the number of key/item pairs in the Dictionary object. |
Item | Sets or returns the value of an item in the Dictionary object. |
Key | Sets a new key value for an existing key in the Dictionary object. |
Methods
Method | Description |
---|---|
Add | Adds a new key/item pair to the Dictionary object. |
Exists | Returns a Boolean value indicating whether the specified key exists in the Dictionary object. |
Items | Returns an array of all items in the Dictionary object. |
Keys | Returns an array of all keys in the Dictionary object. |
Remove | Removes the specified key/item pair from the Dictionary object. |
RemoveAll | Removes all key/item pairs from the Dictionary object. |