ASP 101 - Active Server Pages 101 dictionary.aspx
<%@ Page Language="VB" Explicit="true" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<script runat="server">
	Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
		Dim objColorDict As StringDictionary
		Dim strColor As String
		Dim deColor As DictionaryEntry
		Dim strTemp As String
		' Create a StringDictionary object to hold our color information
		objColorDict = New StringDictionary()
		' Add some keys and items
		objColorDict.Add("black",   "#000000")
		objColorDict.Add("red",     "#FF0000")
		objColorDict.Add("yellow",  "#FFFF00")
		objColorDict.Add("green",   "#00FF00")
		objColorDict.Add("aqua",    "#00FFFF")
		objColorDict.Add("blue",    "#0000FF")
		objColorDict.Add("fuschia", "#FF00FF")
		objColorDict.Add("white",   "#FFFFFF")
		' Display all the keys and items
		strTemp = ""
		For Each strColor In objColorDict.Keys
			strTemp = strTemp & strColor & vbTab
			strTemp = strTemp & "<span style=""background-color: " & objColorDict.Item(strColor) & """>"
			strTemp = strTemp & objColorDict.Item(strColor)
			strTemp = strTemp & "</span>" & vbCrLf
		litAllEntries.Text = strTemp
		' Display the number of pairs in the dictionary
		litCount.Text = objColorDict.Count
		' Check if a key exists
		litBlueExists.Text = objColorDict.ContainsKey("blue")
		' Display a single item by accessing it via its key
		litBlueValue.Text = objColorDict.Item("blue")
		' Change the value of an item
		objColorDict.Item("blue") = "#000099"
		litBlueNewValue.Text = objColorDict.Item("blue")
		' Change the value of a key
		objColorDict.Add("dark blue", objColorDict.Item("blue"))
		' Display all the keys and items again using different syntax
		strTemp = "<table border=""1"">" & vbCrLf
		strTemp = strTemp & "<tr><th>Key</th><th>Item</th></tr>" & vbCrLf
		For Each deColor in objColorDict
			strTemp = strTemp & "<tr>"
			strTemp = strTemp & "<td>" & deColor.Key & "</td>"
			strTemp = strTemp & "<td bgcolor=""" & deColor.Value & """>" & deColor.Value & "</td>"
			strTemp = strTemp & "</tr>" & vbCrLf
		strTemp = strTemp & "</table>" & vbCrLf
		litAllEntriesTable.Text = strTemp
		' Get rid of the dictionary
		objColorDict = Nothing
	End Sub
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
    <title>ASP.NET Dictionary Sample from ASP 101</title>
<form id="myForm" runat="server">
	<p>All the keys and corresponding items in our dictionary object:</p>
<strong>Key	Item</strong>
<asp:Literal id="litAllEntries" runat="server" />
	Number of key/item pairs in our dictionary:
	<asp:Literal id="litCount" runat="server" />
	Does a "blue" key exist:
	<asp:Literal id="litBlueExists" runat="server" />
	Value of the item corresponding to the "blue" key:
	<asp:Literal id="litBlueValue" runat="server" />
	Changing the value of the "blue" key's item.
	Its value is now:
	<asp:Literal id="litBlueNewValue" runat="server" />
	Changing the value of the "blue" key to
	"dark blue".
	<p>All the keys and corresponding items in our dictionary object:</p>
	<asp:Literal id="litAllEntriesTable" runat="server" />
<hr />
Click <a href="">here</a>
to read about and download the source code.