Latest web development tutorials

ASP Dictionary Object

Dictionary object is used in the name / value pairs store information.


Examples

Try - Example

Specified key exist?
This example demonstrates how to create a Dictionary object, and then use the Exists method to check whether the specified key exists.

It returns an array of all items
This example demonstrates how to use the Items method to return an array of all items.

It returns an array of all the keys
This example demonstrates how to use the Keys method to return an array of all the keys.

The return value of a project
This example demonstrates how to use the Item property to return the value of a project.

Set a key
This example demonstrates how to use the Key property to set a key in a Dictionary object.

Back key / item number of pairs
This example demonstrates how to use the Count property to return the key / item number of pairs.


Dictionary Objects

Dictionary object is used in the name / value pairs (equivalent to the key and project) to store information. Dictionary objects seemingly simpler than the array, however, the Dictionary object is a more satisfactory processing solutions related data.

Compare Dictionaries and Arrays:

  • Dictionary object used to identify key projects
  • You do not need to call ReDim to change the size of the object Dictionary
  • When you delete an item from the Dictionary, the remaining items will automatically move
  • Dictionary is not a multi-dimensional, multi-dimensional arrays and
  • Dictionary with more than an array of built-in functions
  • Dictionary when accessing random elements frequently, work better than arrays
  • Dictionary according to their content localization project, work better than arrays

The following example creates a Dictionary object, and adds a number of key objects / projects, and then retrieve the value of the project's key gr:

<%
Dim d
Set d=Server.CreateObject("Scripting.Dictionary")
d.Add "re","Red"
d.Add "gr","Green"
d.Add "bl","Blue"
d.Add "pi","Pink"
Response.Write("The value of key gr is: " & d.Item("gr"))
%>

输出:

The value of key gr is: Green

Dictionary object properties and methods are described below:

Attributes

属性 描述
CompareMode 设置或返回用于在 Dictionary 对象中比较键的比较模式。
Count 返回 Dictionary 对象中键/项目对的数目。
Item 设置或返回 Dictionary 对象中一个项目的值。
Key 为 Dictionary 对象中已有的键值设置新的键值。

method

方法 描述
Add 向 Dictionary 对象添加新的键/项目对。
Exists 返回一个布尔值,这个值指示指定的键是否存在于 Dictionary 对象中。
Items 返回 Dictionary 对象中所有项目的一个数组。
Keys 返回 Dictionary 对象中所有键的一个数组。
Remove 从 Dictionary 对象中删除指定的键/项目对。
RemoveAll 删除 Dictionary 对象中所有的键/项目对。